sub foo { open my $file, "file.txt"; bar($file); close $file; } sub bar { my ($file) = @_; my @lines = <$file>; # do something here }