Each filehandle in Perl counts the number of  lines that have been read from it. (Depending on the value of  $/  , Perl's idea of what constitutes a line may not match yours.) When a line is read from a filehandle (via   readline()  or  <>  ), or when  tell()  or  seek()  is called on it,  $.  becomes an alias to the line counter for that filehandle.