sub func { local $_; # THIS IS THE KEY LINE YOU NEEDED open(READ, "< test.txt"); while() { # print; } close READ; return; } # outputs the final line w/o a problem Files: ree ree1 ree2 $VAR1 = [ 'ree', 'ree1', 'ree2' ]; The file is ree The file is ree1 The file is ree2 Files: ree ree1 ree2 #### use strict; use warnings; sub forEveryOther(&@) { my @aData = @_[1..$#_]; my @aResults; local $_; for (my $i=0; $i < $#aData; $i+=2) { $_ = $aData[$i]; push @aResults, $_[0]->(); } return @aResults; } #### my @people = (bob => 53, peter => 200); my @hello = forEveryOther { "Hello, $_\n" } @people; print @hello; # outputs Hello, bob Hello, peter