in reply to die properly

Set $SIG{__DIE__} to be a reference to the function you want to call when it dies. Check out perlvar for more info.