and for possible further illumination:
$t = 'abcd'; $t1 = 'ababxycdcd'; $t2 = 'ababxycdcd'; $t3 = 'ababxycdcd'; # same as $t2, which is identical to $t1 $t4 = 'ababxycdcd'; # still the same... $t =~ s/bc|xy/pq/; print "\$t is: $t\n"; $t1 =~ s/(ab|xy)/pq/; print "\$t1 is: $t1\n"; $t2 =~ s/(ab|xy)/pq/g; print "\$t2 is: $t2\n"; $t3 =~ s/(ab)|(xy)/pq/g; print "\$t3 is: $t3\n"; $t4 =~ s/((ab)|(xy))/pq\1/g; #capture regex -outer (); grouping () in +side print "\$t4 is: $t4\n"; =head1 OUT Output of C:\_perl\pl_test>perl 440581.pl $t is: apqd matched the 'b' $t1 is: pqabxycdcd parenthesdized the alt; now matches the FIRST +'ab' $t2 is: pqpqpqcdcd added /g (match globally) replaces both 'ab's +and the xy $t3 is: pqpqpqcdcd Shifting parens ==> no change, here $t4 is: pqabpqabpqxycdcd Capturing regex -- 3 'pq' pairs, each pair f +ol by 'ab' or 'xy' =cut
additional example added

In reply to Re^3: Regexp dashes at boundaries by ww
in thread Regexp dashes at boundaries by cormanaz

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.