You seem to be misunderstanding how && works in this case. When you say:

    $_ =~ /a/i && /e/i && /i/i && /o/i && /u/i

that essentially gets extrapolated to:

    ($_ =~ /a/i) && ($_ =~ /e/i) && ($_ =~ /i/i) && ($_ =~ /o/i) && ($_ =~ /u/i)

Then when you write:

    $one_line =~ /a/i && /e/i && /i/i && /o/i && /u/i

it similarly gets extrapolated to:

    ($one_line =~ /a/i) && ($_ =~ /e/i) && ($_ =~ /i/i) && ($_ =~ /o/i) && ($_ =~ /u/i)

Notice how all the subsequent matches look in $_? The only reason your first example works is because the match operator defaults to matching against $_. The solution is either to bind each and every match to the variable you want to match, or to combine all the regexes into one, like so: $one_line =~ /a|e|i|o|u/i.

Update: replies pointed out that my combined regex was not the same as the original intent.

Update: I've posted a single-regex solution deeper in the thread. It may have problems that I'm not aware of, but seems to test out OK.


In reply to Re: $_ works, $my_variable doesn't? by revdiablo
in thread $_ works, $my_variable doesn't? by C_T

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.