eval { my $ssh = Net::SSH::Perl->new($tsip) } if ( $@ ) { # Error } else { # Success }