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)
####
0 = calculated score so far
1 = flag indicating if any card has a value of 10
2 = flag indicating if it is necessary to check for flush
##
##
# Find suits of any jack in the first 4 cards
my %jack = map { $_ => 1 } substr($str, 0, 8) =~ /(?<=J)(.)/g;
# Determine if the suit of the 5th card matches
++$score if $jack{ substr($str, -1, 1) };
##
##
# Get the unique list of suits in the first 4 cards
my %suit = map {$_ => undef} unpack('xAxAxAxA', $str);
# If all the same, count 1 per card
if (keys %suit == 1) {
$score += 4;
# If cut-card matches, add 1 for that too
$score += 1 if substr($str, 1, 1) eq substr($str, -1, 1);
}