in reply to How do I find the total number of lines in a file?

This is a FAQ, answered in perlfaq5.

I quote from that document:

How do I count the number of lines in a file?

One fairly efficient way is to count newlines in the file. The following program uses a feature of tr///, as documented in perlop. If your text file doesn't end with a newline, then it's not really a proper text file, so this may report one fewer line than you expect.

$lines = 0; open(FILE, $filename) or die "Can't open `$filename': $!"; while (sysread FILE, $buffer, 4096) { $lines += ($buffer =~ tr/\n//); } close FILE;

This assumes no funny games with newline translations.



Read the FAQs, memorize the questions, so you know where to look when you need the answer.
perldoc Is a handy tool. perldoc -q count or perldoc -q lines would have given you the answer you wanted.