How can I create a file's full path if it does not exist?

view full story

http://stackoverflow.com – In a function I get a reference to a file. That could be in a format dir1/subdir/filename.txt Is there a way in perl to do: If the file does not exist, create it and the directory structure as well if it does not exist This way guarantees that if 2 scripts try to do the same concurrently nothing will go wrong (e.g. end up with corrupted/locked file etc)? (HowTos)