use strict; use warnings; use File::Temp qw(tempfile); #-- UNLINK => 1: removes the tempfile when program finishes # perldoc File::Temp - shows more usage options my ($fh, $filename) = tempfile( UNLINK => 1); #-- that's it - now display filename... print "Filenme: $filename\n"; #-- or use filehandle... (here: no open()/close() required!) print $fh "lalala\n"; #-- here: file is removed automatically on program exit