my %count; while (...) { my($field1, $field2) = split(...); # assume that we already has the key $field1 in %count # so the value would be $count{$field1}. # # assume it to be array reference, pretend you did: # $count{$field1} = [] # # the push() function requires real array so you need # to dereference it first, like this @{$count{$field1}}, # then push the new value # push @{$count{$field1}}, $field2; }