Search notes:

Perl: regular expression to substitute within matched region

With the e flag, it's possible to first match certain portions of a text and then substitute only those parts that have actually matched.
The substitution matches text between two # (the regex is #(.*?)#) and then turns the matched text into uppercase (using uc).
#!/usr/bin/perl
use warnings;
use strict;

my $text = 'ab cde #fg hi jkl# mn op qrs #tuv wxy# z';

$text =~ s/#(.*?)#/'#' . uc($1) . '#'/ge;

print $text;
#
# ab cde #FG HI JKL# mn op qrs #TUV WXY# z
Github repository about-perl, path: /regular-expressions/substitute-within-matched-region.pl

See also

Perl regular expressions

Index