I usually solve this with a subroutine. I'll provide a few - one for regex matching and two for plain 'contains' or 'equals' matching.

The whole idea here is I'm just sticking the operator into a subroutine and calling each value in turn until either the list is exhausted or something matched successfully. I understand this somewhat of the idea behind the junction operators in perl6. Anyhow, check out List::Util for more thoughts along these lines.

sub qrany { $_ =~ $_[0] && return 1 for @_[1 .. $#_]; return } sub cany { index($_[0],$_) != -1 && return 1 for @_[1 .. $#_]; return + } sub eqany { $_ eq $_[0] && return 1 for @_[1 .. $#_]; return } # Contains tests if (cany( $string, qw[this or_this or_that]) {.... or # Equality tests if (eqany( $string, qw[this or_this or_that]) {.... or # Regex tests if (qrany( $string, qr/one regex/, qr/another regex/, qr/yet another regex/ )) { ....

Updated Added eqany and some comments on the usage of each

UpdatedFixed the words "three and two". Also added the second paragraph


Seeking Green geeks in Minnesota


In reply to Re: matching strings... by diotalevi
in thread matching strings... by powerhouse

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.