in reply to Text markup confusion

You can accomplish this by using the s/// replace function:
my $text = "I saw the panda myself,\nbut Amy did not.\nA var a.my"; my $regexp = qr/(a[ .]*my)/i; $text =~ s/$regexp/'~'.uc $1.'~'/ge; print "$text\n";
gives
I saw the pand~A MY~self, but ~AMY~ did not. A var ~A.MY~
Here, I have tested for optional spaces and periods. Generalization to other punctuation is straightforward.

-Mark