If you have a simple regex replace in perl as follows:
($line =~ s/JAM/AAA/g){
how would I modify it so that it looks at the match and makes the replacement the same case as the match for example:
'JAM' would become 'AAA' and 'jam' would become 'aaa'
Unicode-based solution:
Here the unhandled characters resp. their categories are a bit easier to see than in the other answers.
In Perl 5 you can do something like:
It handles all different cases of JAM, like Jam, and it's easy to add other words, eg:
Something like this perhaps?
http://perldoc.perl.org/perlfaq6.html#How-do-I-substitute-case-insensitively-on-the-LHS-while-preserving-case-on-the-RHS%3f
Doing it in two-steps is probably a better/simpler idea...
Using the power of google I found this