(??{ code })
...
This is a "postponed" regular subexpression. The
"code" is evaluated at run time, at the moment this
subexpression may match. The result of evaluation is
considered as a regular expression and matched as if
it were inserted instead of this construct.
####
1 while s!([BUI])(<+)\s*(.*?)\s*(??{'>' x length $2})!<$1>$3$1>!;
##
##
"B<<< I<< U >> >>>"
##
##
bold underlined text
##
##
my $pod2html = qr/
([BUI]) # start of formatting pattern
(<+) # collect opening braces
\s*(.*?)\s* # collect text, without border space
(??{'>' x length($2)}) # match same number of closing braces
/x;