my %products; for (@lines) { chomp; next unless my ($rep, $prod, $qty) = $_ =~ /(\w+)\s+(\w+)\s+(\d+)/; $product{$prod}{$rep} += $qty; }