use strict; my $filename = "foo.txt"; my $count; open FILE, $filename or die "could not open $filename"; while() { $count++; } # while close FILE; print $count;