my $counter; while ( <$fh> ) { $counter++; print "Line number is : $counter\n"; } #### while ( <$fh> ) { print "Line number is :" . $. . "\n"; }