#!C:\strawberry\perl\bin use warnings; use strict; use Net::SSH2; use MIME::Lite; use Config::Tiny; my $ssh2 = Net::SSH2->new(); my $ipaddr="w.x.y.z"; my $username="username"; my $password="password"; $ssh2->connect("$ipaddr") || die "PROBELM - $!"; $ssh2->auth_password("$username","$password") || die "Username/Password not right"; my $chan = $ssh2->channel(); $chan->blocking(0); $chan->exec('export NAS_DB=/nas;/nas/bin/nas_fs -list'); print "Chan= $chan\n"; my $result; while (<$chan>) { $result=$_; #Desired output. Only works inside the loop. $result='test'; #Used for testing, this works inside and outside of loop #print $result; #Works } print $result; #Works if $result is set, but not with a $_; print "END";