#!/usr/bin/perl -CSDA use utf8; use Modern::Perl; no warnings qw{uninitialized}; use Data::Dumper; use Path::Tiny; my %count; $count{$_}++ for map { $$_[2] } map { [split /\s+/, $_] } path("myfile")->lines_utf8; print Dumper(\%count); $VAR1 = { 'down' => 5, 'NA' => 3, 'up' => 9, 'Regulation' => 1 };