What is wrong with my perl script?

i managed to write a perl script for nagios. now, the script works. but i think there's somethign wrong with the exit codes. because the script doesn't show the output of the results in nagios, it instead shows null.

please tell me what i'm doing wrong here:

#!/usr/local/bin/perl

use STUN::Client;
use Data::Dumper;
use Getopt::Long;
use warnings;
use strict;

my %ERRORS = ( OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 );

my $timeout = 30;

$SIG{ ALRM } = sub {
   print "CRITICAL: Timeout expired (${timeout}s) before server responded.";
   exit $ERRORS{ CRITICAL };
};

my $server = $ARGV[0];

my $userip = $ARGV[1];

my $stun_client = STUN::Client->new;

$stun_client->stun_server("$userip");

my $r = $stun_client->get;

if ($r eq '')
{
   print "CRITICAL:  Did not receive a response from the device = [ $server, $userip ]\n";
   exit $ERRORS{CRITICAL};
}

my $ip = $r->{ma_address};

my $transid = $r->{transaction_id};

my $portreturned = $r->{ma_port};

# Split the IP address into an array of octets

my @x = split /\./, $ip;
 
# Print it unless it is invalid


if (($#x != 3 or grep {$_ =~ /\D/ or $_ < 0 or $_ > 255} @x) && ($transid eq '') && ($portreturned eq ''))

{

   print "CRITICAL:  IP returned is not a public IP. Response from query  ==  IP [ $ip ], TranID [ $transid ], Port [ $portreturned ].\n";
   exit $ERRORS{CRITICAL};
}

else

{

   print "OK: Response received from device [ $server ] is sufficienct  ==  IP [ $ip ], TranID [ $transid ], Port [ $portreturned ].\n";
   exit $ERRORS{OK};
}

Not sure.

But anyway following line misses newline - try with newline.

    print "CRITICAL: Timeout expired (${timeout}s) before server responded.";

thanks for responding to me. i tried that. but it's still not passing.

Nagios is a monitoring application that works based off the "exit codes" it receives. it looks like this script isn't sending the proper exit codes. i dont know what i'm missing.

the code seems to be having an issue with the "exit $ERRORS"