my %seen; for my $arrayref (@all_inputs) { if ($arrayref->[0] && $arrayref->[1]) { # not interesting, just pass it through print_result($arrayref); } else { # get a signature, increase the count for that signature by 1 ++$seen{ signature($arrayref) }; } } # now construct combined results for the saved inputs for my $sig (keys %seen) { my $count = $seen{$sig}; my $arrayref = [ split /\./, $sig ]; # keep it easy: multiplying the zero value is a noop $arrayref->[$_] *= $count for (0, 1); print_result($arrayref); }