in reply to Re: Regular expression Problem
in thread Regular expression Problem

As far as I can tell, those two regexes are identical: one as a plain match, and one as a substitution.
I'm guessing somebody is first testing to see if anything is found, and if it does, replace it.
Don't do that. Just plain s/// is enough, it won't do anything if nothing is found, so it's safe.

And if it happens to be the case that the existence of a match is used to conditionally control more than just a substitution, the  s/// operator returns the number of substitutions done, or false if there is no match, so it works just fine as a conditional expression. See s/PATTERN/REPLACEMENT/msixpogce in perlop.

>perl -wMstrict -le "my $str = 'foo'; ;; if ($str =~ s{ foo }{bar}xms) { print qq{substituted with $str}; } " substituted with bar