use strict; use warnings; my @categories=qw/a b c/; my @master; #replace this line with a while statement+chomp+split #foreach my $d(@data){ while (my $line = ) { chomp $line; my $d = [ split(m{,}, $line) ]; my %h; foreach my $c(0 .. $#categories){ my $val=$d->[$c]; my $cat=$categories[$c]; $h{$val}=$cat; } push @master, \%h; } __DATA__ 1,2,3 4,5,6 7,8 10,11,12