Using while loop to calculate the number of lines in a file
$number_lines = 0;
open(FILEHANDLE, "file.txt") or die "Can not open file.txt";
while (<FILEHANDLE>) {
++$number_lines;
}
close FILEHANDLE;
print "The number of lines in file.txt = $number_lines.";