in reply to Highlighting only captured groups from larger regex

Similar solution, but not with single regex:
#!/usr/bin/perl use strict; use warnings; # https://perlmonks.org/?node_id=11148806 my $text = 'This is arbitrary just an arbitrary just example of text j +ust arbitrary.'; @_ = qw( ju.. arb.{1,4}ary ); $text =~ m/ (?:(?:This)|(?:That)) .*? (??{ $_[ 0 ] }) .*? (??{ $_[ 1 ] }) /x and $text =~ s/ (??{ "(*FAIL)" x ! @_ }) .*? \K ( (??{ $_[ 0 ] }) ) (?{ shift @_ }) /<<<$1>>>/gx; print $text, "\n";
OUTPUT (excluding warnings):
This is arbitrary <<<just>>> an <<<arbitrary>>> just example of text j +ust arbitrary.
P.S. capture group is redundant.