perl -we "sub fail{die 'test'}; END{ print qq'\nF\n'; fail() }; $SIG{__DIE__} = sub{print qq!\nS\n!; fail()}; fail()" S test at -e line 1. F S S test at -e line 1.