You are being confused by list context vs. scalar context. Compare and contrast the version below.

my $test_line = 'Happy Birthday'; my ( $parse1, $parse2 ) = $test_line =~ /(Happy)(.*)/; print "parse1 = $parse1\nparse2 = $parse2\n";

The match in list context returns the matches. Excerpts from perlop:

m/PATTERN/msixpodualgc /PATTERN/msixpodualgc Searches a string for a pattern match, and in scalar co +ntext returns true if it succeeds, false if it fails. If no +string is specified via the "=~" or "!~" operator, the $_ stri +ng is searched. (The string specified with "=~" need not be +an lvalue--it may be the result of an expression evaluatio +n, but remember the "=~" binds rather tightly.) See also perl +re.
Matching in list context If the "/g" option is not used, "m//" in list context r +eturns a list consisting of the subexpressions matched by the parentheses in the pattern, that is, ($1, $2, $3...). +(Note that here $1 etc. are also set, and that this differs f +rom Perl 4's behavior.) When there are no parentheses in the pa +ttern, the return value is the list "(1)" for success. With o +r without parentheses, an empty list is returned upon fai +lure.

In reply to Re: Regex question by mr_mischief
in thread Regex question by DoubleBond

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.