in reply to Pattern match

Could you provide a code sample to demonstrate your problem? (Something that we could run, that's short, and where the result is not the one you expect see How do I post a question effectively?). Because right now, the answer that can be given to you is "it doesn't.

If you are going for an exact match, index might just do the trick for you (it's understood by more people, less side effects and unexpected behavior, faster)

Replies are listed 'Best First'.
Re^2: Pattern match
by exploreperl (Initiate) on Dec 05, 2014 at 00:07 UTC
    Following is a sample code: if ($_ =~ m/received 486 response to blah/){ do this; } else{ do that; } However this doesn't seem to work correctly, because when a portion of the string is "received 480 response to blah" it still matches and breaks the logic.

      when a portion of the string is "received 480 response to blah" it still matches
      Your regex does not match 'received 480 response to blah', so either your error is somewhere else in your code, or as stated by GrandFather, your string $_ contains both the 486 and 480 variations.

      When we say "runnable code", we mean something that we can copy and run, and that will actually do something. If I run: perl -e 'if ($_ =~ m/received 486 response to blah/){ do this; } else{ do that; }' nothing happens.