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 #### use Net::Telnet; use warnings; use strict; my ($file, $str); open $file, ">", \$str; my $t = new Net::Telnet(timeout => 10, input_log => $file, Prompt => "/\[AAUA1\]/"); $t->open("foo"); $t->login("me", "hi"); $t->cmd("pwd"); $t->cmd("whoami"); $t->close(); print "\$str content:\n"; print $str;