use strict; use warnings; use Try::Tiny; $SIG{__DIE__} = sub { chomp(my $item = shift); print STDERR "DIE ERROR: $item\n"; exit 2; }; # ... code here ... my $last_sig_die = $SIG{__DIE__}; # Save current setting $SIG{__DIE__} = 'DEFAULT'; try { die 'Dying'; } catch { print STDERR $_; # Note: $_, not $@ }; $SIG{__DIE__} = $last_sig_die; # Restore setting die 'Really dying';