Perl: fixed crash when a script exits abnormally

Test script: https://dl.dropboxusercontent.com/s/3jbr48lh6rpkgrz/crash.pl
1) Start HexChat
2) Load script
3) Connect to a network
4) Wait to get at least two notices