in reply to Improving Efficiency

If you set $/ to an integer,  <...> reads as many characters each time. Then use tr as in BrowserUks post to count the zeroes.

use strict; use warnings; my $total_filtered = 0; open my $cgs, "<", "count.txt"; $/ = \10000; # blocksize $total_filtered += tr/0/0/ while <$cgs>; print "Found $total_filtered zeroes.\n";

UPDATE: Changed 10000 to \10000 as a reference is needed. Thanks to Anonymous monk below!

Replies are listed 'Best First'.
Re^2: Improving Efficiency
by Anonymous Monk on Sep 01, 2013 at 18:36 UTC
    ... works when counting single characters but could fail to count a multi-character sequence that falls right along the read-chunk boundary (such that one-half is in one read and the other half is in the other). ... could also present more-serious problems if the characters being sought (or any characters) are multibyte.