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