If all you want is to send a trap to test your trap receiver, you don't have to write a script! You can just download and install the net-snmp command line tools from
http://net-snmp.sourceforge.net/download.html
The command "snmptrap" is just what you're looking for.
If you want to do this from a shell script, of course you just ahve the script call the snmptrap binary.
If you are actually writing some monitoring script in perl, I still think the easiest way is to execute the snmptrap program from the perl script. You do also have the option of using some SNMP library. I've used Net::SNMP (unrelated to net-snmp) to good effect:
https://metacpan.org/pod/Net::SNMP