use Path::Class qw( file ); my $file = file '/tmp/foo/bar/baz.txt'; $file->dir->mkpath; print { $file->openw } "Hello world!\n";