in reply to Case-sensitive substitution with case-insensitive matches

My initial thought for the capitalization is something like this:

s/(bad)/my $str = "sad"; if (substr($1, 0, 1) eq 'B') { ucfirst $str }; $str/gie;

but that strikes me as ugly. Another approach would be building a hash with the possibilities:

my %insens = ( bad => 'sad', Bad => 'Sad', bAd => 'sAd', ); s/(bad)/$insens{$1}/gi;
Build the hash programmatically if necessary.