in reply to Keeping track of Pairs

You're looking for something like this:
# without using hashes, as you requested sub group_cards_nohash { # convert initial string param into a sorted list of cards my @cards = sort { $a <=> $b } split / /, shift; my @tally; my $cnt = 1; # generate running tally of cards - we're going to remove # cards one at a time from the list, until it's empty while (@cards) { # remove a card my ($card, $tally) = (shift @cards, 1); # remove successive cards until there are none left, or # a card of a different value is encountered while (defined $cards[0] and $cards[0] == $card) { shift @cards; $tally++; # increment tally for every identical card } # add this tally to the results push @tally, $tally; } # return the tally sorted in reverse sort { $b <=> $a } @tally; } # though it's much more straightforward with the hash-based approach b +elow sub group_cards_hash { # convert initial string param into a sorted list of cards # notice that we don't need to sort this one my @cards = split / /, pop; my %tally; # tally the cards $tally{$_}++ foreach @cards; # return the tally sorted in reverse sort { $b <=> $a } values %tally; } print join ',', group_cards_hash('9 9 5 5 1'); print "\n"; print join ',', group_cards_nohash('9 9 5 5 1');
   MeowChow                                   
               s aamecha.s a..a\u$&owag.print