use strict; use warnings; use File::Temp qw/ tempfile tempdir /; my $dir = tempdir(); my ($fh, $filename) = tempfile( DIR => $dir ); print "Temporary file '$filename' created.\n"; print $fh "Stuff you want in the file.\n";