I've done a few hours of Googling and can't seem to find the solution.

I want to check if an array of single words (strings) contains several specific words, in any order.
I have this code, cobbled together from advice found online:

my %hash = @allwords; #puts array in hash to search / compare. if (exists $hash{'word1' && 'word2' && 'word3'}) { ...do stuff ; }

I want the if to be true if all the words are found, in any order. But it's returning true
if just word3 is found. I think it's ignoring word1 and word2.
I'm too new at Perl to know if it's even appropriate syntax, although it doesn't give any error currently.
I've also found a technique using $_ eq, but it doesn't seem to be matching the way I want:

if ( grep { $_ eq 'word1' && 'word2' } @allwords ) { ...do stuff; }

Keep in mind, I never found any solution to match several values; so this && tactic is a semi-educated guess.

p.s. I don't know why the code format is so tiny in the preview.. I can hardly read the code. But hopefully
it's not that way when I post it.


In reply to Check array for several matches by Bman70

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.