# Try to make the directory in case it doesn't exists. mkdir($dir); # or mkpath($dir); opendir($dir) or die("Unable to open dir \"$dir\": $!\n"); ...