use strict; use warnings; use Data::Dumper; my %hist; while () { chomp; my ($col0, @element) = split; $hist{$col0}{$_}++ for @element; }; print Dumper \%hist; # not repeating the __DATA__ section here