reads the first line of the first file. Then the loop
reads ALL the remaining lines in the files. By the time it gets to
it has exhausted the files, and it reads from stadard-input. <CTRL>D passes end-of-file to standard-input (by default) but that is probably not what you want. If you want each loop to be read for each file then it is probably easier to explicitly
the files instead. You could instead detect when the first file is closed and the second one opened using $ARGV, but that would be messy.