my $buffer ; while (sysread TEXT, $buffer, $buffer_size) { ## This will use tr to count fast for you: $words += ($buffer =~ tr/ +\n+,://) ; }