my $ssh2 = Net::SSH2->new(); $ssh2->connect($rip) ( $code, $error_name, $error_string ) = $ssh2->error(); if ( $code ); # $code will be false (undef) if there is NO error. { print "$code: $error_name: $error_string \n"; #format as you wish :) exit(); } ...