my %card; ++$card{$_} for @hand; $score += $_ * ($_ - 1) for values %card; # 1 * 0 = 0 (0 points for 1 of a kind) # 2 * 1 = 2 (2 points for 2 of a kind) # 3 * 2 = 6 (6 points for 3 of a kind) # 4 * 3 = 12 (12 points for 4 of a kind)