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