Re: replace strings and preserve case

2002-11-06 Thread John W. Krahn
David Garamond wrote: > > is there a short recipe to do this in perl? i want to replace all "die" > with "paint" and preserve case (i.e. "Die" should be replaced by > "Paint", "DIE" by "PAINT", and so on). there's a smart snippet on TPJ to > do this: > > $string =~ s/($x)/"\L$y"^"\L$1"^$1/ie; >

replace strings and preserve case

2002-11-06 Thread David Garamond
is there a short recipe to do this in perl? i want to replace all "die" with "paint" and preserve case (i.e. "Die" should be replaced by "Paint", "DIE" by "PAINT", and so on). there's a smart snippet on TPJ to do this: $string =~ s/($x)/"\L$y"^"\L$1"^$1/ie; but it only works if the replacemen