use File::Path 'make_path'; File::Path->make_path($path); chdir $path or die "Cannot chdir: $!";