in reply to Pattern Matching: Case-Conservation

Here's yet another way to do it. Don't be too distracted by the /x modifier which allows for whitespace in the RE. I just did that to hopefully make it a little easier to read.

All the 'work' is done inside the right side of the s/// operator. @array is there just to demonstrate that it works on every possible combination of foo.

use strict; use warnings; my @array = qw/foo Foo FOo FOO fOO fOo foO FoO/; my $repl = 'bar'; print "@array\n"; s{ \b(foo)\b }{ join '', map { substr( substr( $1, $_, 1 ) ge 'a' ? lc $repl : uc $repl, $_, 1 ) } 0 .. $+[0] }eix foreach @array; print "@array\n";

Enjoy!


Dave