# 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); }