use Net::SSH::Any; my $ssh = Net::SSH::Any->new($ipaddr, user => username, password => $password); $ssh->error and die "Unable to connect to $ipaddr: " . $ssh->error; my @lines = $ssh->capture('/nas/sbin/getreason'); for (@lines) { next if /10 - slot_0 primary control station/; if (/contacted$/) { print $mailfh "DM is OK: $_\n"; } else { print $mailfh "POSSIBLE DM FAILURE:Please check $ipname ($ipaddr): $_ POSSIBLE DM FAILURE:\n"; } }