eval { #code you want to catch errors from }; custom_error_handler($@) if $@;