in reply to When does while set $_ ?

it is known special case that
while (<FILEHANDLE>) { }
made to read into $_ variable. Either save it's value by "local" operator, or use following special-case construct:
while ($var_to_receive_a_line = <FILEHANDLE>) { }