my %table; while () { chomp; my @line = split /,/; my $key = join ",", @line[1..3]; if ( exists( $table{$key} )) { warn "oops -- duplicate key $key... is there a problem with that?\n"; next; # just in case there's a problem with that } $table{$key} = join ",", @line[4,5]; } # later on, if you really need the individual columns from the # hash key or the hash value, just use "split /,/" as needed # # note that you can easily search for groups of hash keys: my @root23keys = sort grep /^23,/, keys %table; my @r23p34keys = sort grep /^23,34,/, keys %table; # and so on... __DATA__ 1,2,3,4,100,A 10,20,30,40,200,B 11,21,31,41,300,C 12,22,32,42,400,D 13,23,33,43,500,E 13,23,33,53,600,F 13,23,33,63,700,G 13,23,34,73,800,H 13,23,34,83,900,I 13,24,35,93,1000,J 13,24,36,103,1100,K