my $fh; if (! open $fh, '<', $file){ die $!; } # you can successfully use fh here... # it'll only close if you "close $fh or die $!;", or when the file (program) exits # the above example has the same effect of doing the below example, but this is # easier as you don't have a bunch of variables declared at the top of your file. # the entire idea is to keep variables declared, defined as close to # the place you intend to use them open my $fh, '<', $file or die $!;