$ wc words.txt 113809 113809 1016714 words.txt #### $ perl -ne 'chomp; for my $let (A..Z) { print "$_ ". "foobar" x 200, " $let\n" }' words.txt > test_file.txt $ wc test_file.txt 2959034 8877102 3586152466 test_file.txt #### use strict; use warnings; use feature qw/say/; my %histogram; open my $IN, "<", "test_file.txt" or die "could not open input file $!"; while (<$IN>) { chomp; my ($key, undef, $val) = split / /, $_; $histogram{$key}++ if defined $val and $val eq 'Z'; } print scalar keys %histogram; #### $ time perl test_Z_bigfile.pl 113809 real 0m13.973s user 0m11.734s sys 0m2.140s