use strict; use warnings; use Data::Dumper; my %report; my $nameCount=0; my @names = map { $_.++$nameCount } ('Key', ) x 10; # Here the names will be Key1 to Key10, # But you should actually give explicit names with something like # my @names = qw/Princess Leia Obiwan Kenobi Anakin Skywalker Darth Vader Han Solo/; while (my $line = ) { my %fields; @fields{@names} = (split / /, $line); # Here we put the result into a slice of %fields foreach my $name (@names) { my $value = $fields{$name}; $report{$name}{$value}++; # Auto vivification here, $report{$name} magically becomes a hashref } } print Dumper \%report; __DATA__ 483 OS dx-32 1 charles list4 aardvark.com ty-off lx-on C 01 483 DS dx-14 1 james list3 23.456.12.7 ty-on lx-on B 01 769 XO dx-32 5 sully nolist widgets.com ty-on lx-on V 07