my $ok = eval { # code that might call die to signal that something has gone wrong ... return 1; } or do { # error handler code my $error = $@; ... };