N00bie alert

I've tried to use the following expression:
if ($string =~ m/(p1)(p2)(p3)/) { rest of block
which captures p1 into $1 p2 into $2 and p3 into $3 as I expect it should.
the question is this: when I try to substitute:
($new1 = $1) =~ s/this/that/;
($new2 = $2) =~ s/this2/that2/;
($new3 = $3) =~ s/this3/that3/;  (and so on)
I get a runtime error (uninitialized value) even though, for the exact same $string and m// when I split the expression into:

$new1 = $1;
$new2 = $2;
$new3 = $3;
$new1 =~ s/this/that/;
$new2 =~ s/this2/that2/;
$new3 =~ s/this3/that3/;
I don't get a runtime error (undefined or other).

I didn't think I was modifying $1 ($2 or $3) so thought the initial substitution should work. I'm wondering what I missed in this case.

thanks in advance


In reply to modifying en passant by lcschreier

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.