my $n = 0; my $result = undef; eval { $result = 10 / $n; }; if ($@) { print "can't do that!\n"; } else { print "here's your answer: $result\n"; }