Trying to execute perl shell command in nagios plugin


hi, i am a newbie in nagios and perl. i am trying to execute a shell command using perl and manipulate the return value.

the command is :

$result = /usr/sbin/asterisk -rx "sip show peers" |grep "512" | awk '{print $4}' ;

when i run the plugin from the shell (as in do like : ./check_sip_extension 512 ) it seems to return a value. but from within nagios it does not return anything.

does anyone have any idea what am i doing wrong?