use warnings; use Net::SSH2; use Data::Dumper; my $ssh = Net::SSH2->new(); # make a global hash for storage my %hash; # make a global counter for incrementing the hash keys my $counter = 0; ...... ...... if($ssh->auth_ok()) { runcmd(my_channel($ssh), "$bigcmd"); } # read output ( but lines may be split ) print $DATA::Dumper( \%hash ),"\n"; __END__ sub runcmd { my ($channel, $command) = @_; $channel->exec($command);# or die $@ . $ssh->error(); my $buff; while(!$channel->eof()) { my $buff; $channel->read($buff, 1024); # print $buff; $hash{$counter} = $buf; $counter++; } my $rc = $channel->exit_status(); $channel->close(); return $rc; }