$fname = "$0"; open(TEXT, "<$fname")|| die "could not open file: $fname\n"; ## Let's read 100KB per time. my $buffer_size = 1024*100 ; my ($buffer,$words) ; while (sysread TEXT, $buffer, $buffer_size) { ## This will count fast for you: my @c = ($buffer =~ /( +\n+,:)/gs) ; $words += @c ; } close TEXT; print "Length: $words\n" ; exit;