sub foo { my ($filename) = @_; open my $file, "<", $filename or die "blah :$!\n"; while (<$file>) { # etc } # explicit call to close not needed. }