use warnings; use strict; my $str; open FILE, ">", \$str; print FILE "abcd\n"; print FILE "1234\n"; print $str;#the content is there before close close FILE; print $str; #the content is still there after close