Perl only resets the line counter when opening the file. For each line in $remedy_file, you read many lines of $interface_data. It seems very inefficient to me, but that's a different issue. If, instead of seeking, you would just (re)open the file, you'll see more sensible numbers.