use warnings; use strict; use File::Temp qw/tempfile/; my $fh = File::Temp->new(); print "$_\n" for 0 .. 4; $fh->seek( 0, 0 ); print for <$fh>; close $fh #### 0 1 2 3 4 #### ... use IO::File; my $fh = IO::File->new_tmpfile or die $!; ...