[Solved] Count matches between specific substrings


You can separate each target section of the string into an array using split.
Then iterate through the array and do your count.

my $string = 'AAAAaaa>1BBbbbbbbb>2CCCCCCCCccccc>3DDDDDDDDDddd>4FFFFfffffff>';

my @targets = split(/(?=\d+\w+>)/, $string);
my $successes = 0;

foreach my $target (@targets){
    my $target_lc = $target =~ tr/a-z//;
    my $target_uc = $target =~ tr/A-Z//;

    if($target_lc > $target_uc){
        $successes++;
    }
}

print $successes;

OUTPUT = 2

4

solved Count matches between specific substrings