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