# have to search a little differently for nested tags # making sure that an ending tag belonging to # a nested opening tag is not processed as the ending # tag for the current opening tag. # In case i sounded awkward, here's a little diagram: # # <--- this tag # <--- nested open tag # <--- end tag for the nested open tag # <--- end tag for this tag (the one that has # to be picked up) # # Actual example: # @chunks = # . . . . . . # 5 "\cJ\cI " <--- chk_i, found_i # 6 "\cJ\cI\cI " # 7 "\cJ\cI\cI " # 8 "\cJ\cI " # 9 "\cJ\cI\cI \cJ\cI BOOL is true!\cJ" # 10 "\cJ\cIBOOL is false!\cJ" # 11 ' <--- after: found_i my $opening_tag = $rules->{tag_start}[0] . $tag_name; my $nested = 0; # count of nested open tags found. while ((($chunks[++$found_i] =~ m/^$closing_tag/) ? ($nested > 0 ? $nested-- : 0) : ($chunks[$found_i] =~ m/^$opening_tag/ ? ++$nested : 1)) && $found_i < @chunks) {}