my $ok = eval { do_something(); 1 }; if (! $ok){ handle_exception(); # possibly use contents of $@ }