my %typeCounts; $typeCounts{$_->{type}}++ for (@parsedOutputTokens); print $csvFileHandle "$_, $typeCounts{$_}\n" for keys %typeCounts;