sub fred { open(FH, "< f.tmp") or die "open error f.tmp"; # ... process file here die "oops"; # if something went wrong close(FH); } eval { fred() }; if ($@) { print "died: $@\n" } # Update: this is better, see: [id://11130946] # my $ok = eval { fred(); 1 }; # if (!$ok) { print "died: $@\n" } # oops, handle FH is still open if exception was thrown.