eval { # do something that might go wrong $a = 1; $b = 0; print $a/$b; }; if ($@} { print "Something went wrong: $@\n"; }