local $SIG{__DIE__} = sub { # get error message my $err = $_[0]; # open error log or exit - you can't die here :) open(ERRLOG,'>>/path/to/errlog') || exit(0); # you may want to add information from the caller() # function here and add other info to log print ERRLOG "Error: $err\nplus whatever else you need...\n\n"; close(ERRLOG); exit(0); }