in reply to the variable is lost

foreach ($a, $b)
This makes $_ an alias to $a and $b.
while (<$fh>)
This modifies $_, and hence, modifies $a and $b. Note that the final value will be undefined.