in reply to s///g within m//g regions

s{ ( ^ \#[ ]START \n ) ( .*? ) ( ^ \#[ ]END \n ) }{ $1 . ( $2 =~ s/^[ $]*//rg ) . $3 }xsmeg;

Replies are listed 'Best First'.
Re^2: s///g within m//g regions
by almr (Beadle) on Nov 09, 2021 at 15:52 UTC

    Yes! Except the above breaks, because the inner s/// kills the existing capture groups. So, those must be saved. E.g.

    s{ ( ^ \#[ ]START \n ) ( .*? ) ( ^ \#[ ]END \n ) }{ my @m = @{^CAPTURE}; $m[ 0 ] . ( $m[ 1 ] =~ s/^[ #]+//rmg ) . $m[ 2 ]; }xmesg;

      @{^CAPTURE} is new to me!

      (hmm, I wonder if String::Substitution can be optimized on version where this is available.)