Problem with one substitution modifying another

I have a data file with problems similar to this:

Modeling ?? f and

Where the question marks are non-ASCII characters that were converted to ? when the data was saved to a text file. I have to ferret out these examples, but the problem I'm having with my substitution script is that one substitution command is effect another.

So for example, this line in the script:

my $text;

if ($text !~ /GREP0/) {s/([A-Za-z0-9]* *[A-Za-z0-9]* \?\?[^A-Z0-9]+[^ ]+)/\nGREP01a\: $1 \n/g;}

will change this text:
Modeling ?? f and A
GREP01a: Modeling ?? f and A

Which is exactly what I want, but I'm find out another command line - there are 15 or so - is matching that and changing it.

Basically, if a substitution is made then I don't want that string touched by the other substitution commands. I thought adding the if ($text !~ /GREP0/) - since the substitution would add GREP0 to any string changed - would solve this, but this hasn't been the case.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

In the if, you are checking $text but, in the substitution, you are changing $_.  You need to use one or the other.  The below should work.
unless (/GREP0/) {s/([A-Za-z0-9]* *[A-Za-z0-9]* \?\?[^A-Z0-9]+[^ ]+)/\nGREP01a\: $1 \n/g;}

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
one way could be something like
  s/sub1/replace1/ || s/sub2/replace2/ || s/sub3/replace3/ || s/sub4/replace4/;
another might be something like
  s/sub1|(sub2|(sub3|(sub4)))/${[qw(replace1 replace2 replace3 replace4)]}[!!$1+!!$2+!!$3]/;
but could you give an example of when  adding the if ($text !~ /GREP0/) - since the substitution would add GREP0 to any string changed - did not solve the case?
is it because you are testing $text and changing $_? or is it because one of the substitutions did not add GREP0?
hadronsAuthor Commented:
Thanks to the both of you - you were both correct about me not setting the default variable correctly. I tested both by changing by adding my $text = $_; and then later on changing the if statements to unless and I liked the unless results better.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Regular Expressions

From novice to tech pro — start learning today.