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;