use warnings; use strict; my $text = <<'EOT'; I am IntErEsted in making changes to the following lines. However, START thE chAnges mUst bE \CME madE hErE. END There may be cases whErE START chAngEs nEEd to be mAdE \CME hErE tOO. END EOT $text =~ s{ (?<= START) (.*?) (?= END) } { (my $replacement = $1) =~ s{ (?## [[I am IntErEsted in making changes to the following lines. However, START the changes must be \CME made here. END There may be cases whErE START changes need to be made \CME here too. END ]]