It's not clear to me exactly what you're trying to do, but I wonder if perhaps you need an  | "ordered alternation" operator:

c:\@Work\Perl\monks>perl -wMstrict -le "my $p1 = qr{ Foo }xms; my $p2 = qr{ Bar }xms; my $p3 = qr{ Zot }xms; ;; my $str = 'Bar'; ;; if (my ($m) = $str =~ m{ \A ($p1 | $p2 | $p3) \z }xms) { print qq{matches: has '$m'}; } " matches: has 'Bar'

Update:

my ($m1) = $output =~ /^(pattern1)$/ or my ($m1) = $output =~ /^(pattern2)$/ or my ($m1) = $output =~ /(pattern3)/
BTW: An expression like the one quoted above, with multiple masking variables (i.e., variables having the same name) defined in the same scope is never a good idea, and Perl would have told you about this ugly situation had you enabled warnings with a  use warnings; statement at the top of your program. Especially for those just starting with Perl, always  use warnings; and  use strict; at the start of your code.


Give a man a fish:  <%-{-{-{-<


In reply to Re: Match a Variable to Only the True Statement by AnomalousMonk
in thread Match a Variable to Only the True Statement by razmeth

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.