in reply to Regex: Case insensitive search but case sensitive replace

Well, replacing 'Jane' (any case) with '##Jane##' (same case) is trivial: s/(jane)/##$1##/ig; will do.

But let's say you want to replace 'Jane' (any case) with 'Mary' (same case). Here's one way of doing it:

#!/usr/bin/perl use strict; use warnings; my $pat = "jane"; my $repl = "mary"; while (<DATA>) { s/($pat)/$1 ^ $pat ^ $repl/eig; print; } __DATA__ jane janE jaNe jaNE jAne jAnE jANe jANE Jane JanE JaNe JaNE JAne JAnE JANe JANE mary marY maRy maRY mAry mArY mARy mARY Mary MarY MaRy MaRY MAry MArY MARy MARY