# use eval eval{ # your code here }; if( $@ ) { # error handling code here } # ... or use $SIG{ __DIE__ } $SIG{ __DIE__ } = sub{ # error handling code here } # your code here