use strict; use warnings; sub handler { open FH,">a"; print FH @_; } $SIG{__DIE__}=\&handler; close STDERR; die "Exit from the program";