On Feb 1, Booher Timothy B 1stLt AFRL/MNAC said: >Hello, I am trying to change all files in a directory that contain the >strings Satellite satellite and SATELLITE that I need to change to target, >Target and TARGET. Because many of these are C++ source files I need to >preserve the case. I was thinking of the following script: There's an entry in the Perl FAQ for preserving case, but there's a much simpler way: sub case { my ($s, $d) = @_; $s = substr($s, 0, length($d)) if length($d) < length($s); $d ^ (~$s & (" " x length $s)); } Try it out: for (qw( satellite Satellite SATELLITE )) { print case($_ => "target"), "\n"; } The output is target Target TARGET Its usage in a s/// is: s/(word to change)/case($1, "word to become")/eg; -- Jeff "japhy" Pinyan japhy@pobox.com http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ ** Look for "Regular Expressions in Perl" published by Manning, in 2002 ** <stu> what does y/// stand for? <tenderpuss> why, yansliterate of course.Thread Previous | Thread Next