use warnings; use strict; { open my $fh, '<', 'a.txt' or die $!; # do stuff with file handle } # file handle is closed here # in fact, the $fh isn't even accessible here at all