use File::Temp qw/tempfile tempdir/; my $template = "testtempfileXXXX"; #my $dir = tempdir(CLEANIP=>1); #won't remove temp dir after running my $dir = File::Temp->newdir(); #will remove temp dir after running my ($fh,$path) = tempfile($template, SUFFIX=>".data", UNLINK=>1, DIR=>$dir); print "the path is: $path\nthe dir is: $dir\n";