$SIG{__DIE__} = sub { print STDERR @_; print STDOUT ...; # whatever you want exit(1); };