How to avoid return code of 141?

I have a script that logins into a Cisco switch via SSH and does a ping to another IP. This script is used as a check for nagios. I only want an exit codes of either 2, 1, 0 for fail, warn, ok, respectively. However, when I implement this code in nagios, I sometimes get a return code of 141. Is there some way I can avoid this?

#!/usr/bin/perl
#
# Use: usr/local/sbin/check_cisco_ping_ssh <host> <port> <user> <pass> <ip> <warn> <crit>
#
#use strict;

use Net::SSH::Perl;

$ENV{'HOME'} = '/var/lib/nagios';

my $router=$ARGV[0];
my $port=$ARGV[1];

my $user=$ARGV[2];
my $pass=$ARGV[3];

my $ip=$ARGV[4];

my $warn=$ARGV[5];
my $crit=$ARGV[6];


my $sesion_ssh = Net::SSH::Perl->new($router, protocol=>1,2, cipher=>'DES', port=>$port, debug=> 'false', use_pty=>0);
$sesion_ssh->login($user, $pass);

my $command="ping $ip";

my($output, $output_error, $value_exit) = $sesion_ssh->cmd($command);

$output =~ /Success rate is (\d*) (.*)/;

my $rate=$1;

if ( $rate <= $crit ) {
        print "PROBLEM: $ip is DOWN Rate=$rate%\n";
        exit(2);
}

if ( $rate <= $warn ) {
        print "WARNING: $ip is at Rate=$rate%\n";
        exit(1);
}

if ( $rate <= 100 ) {
        print "OK: $ip is UP Rate=$rate%\n";
        exit(0);
}

exit(3);