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

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1758201035, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/Perl/regular-expressions/substitute-within-matched-region(54): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78