# make a global array for storage my @array; #or make a global scalar string my $storage_string; ..... ..... while(!$channel->eof()) { my $buff; $channel->read($buff, 1024); # print $buff; push @array, $buf; # pushes $buf into next array slot # or use a concated string $storage_string .= $buf; # concantates $buf onto end of string } #### $/ = ''; # change output separator to nothing instead of newline print @array, "\n"; #### my @lines=split( /\n/, $storage_string); print "@lines\n"; # or since $storage_string contains embedded newlines, just printing it would work print "$storage_string\n";