my %count; while (){ next unless /something/; if (//){ $count{$3}++ if $3; } }