use IO::File; my $temp_fh = IO::File->new_tmpfile or die "Could not open a temporary file: $!"; #Save some stuff in the file handle $temp_fh->print('this stuff to the file handle'); #Rewind to the beginning $temp_fh->seek(0, 0); #It can do anything that a normal IO::File file handle can while(my $line = <$temp_fh>) { print $line; #prints 'this stuff to the file handle' }