Run your program with
perl -Mre=debug prog.pl
and you'll get clues
Compiling REx "XXX \(" Final program: 1: EXACT <XXX (> (4) 4: END (0) anchored "XXX (" at 0 (checking anchored isall) minlen 5 Compiling REx "(XXX [^,]+)," Final program: 1: OPEN1 (3) 3: EXACT <XXX > (5) 5: PLUS (17) 6: ANYOF[\0-+\--\377][{unicode_all}] (0) 17: CLOSE1 (19) 19: EXACT <,> (21) 21: END (0) anchored "XXX " at 0 floating "," at 5..2147483647 (checking anchored) + minlen 6 Compiling REx ";" Final program: 1: EXACT <;> (3) 3: END (0) anchored ";" at 0 (checking anchored isall) minlen 1 Compiling REx "\)$" Final program: 1: EXACT <)> (3) 3: EOL (4) 4: END (0) anchored ")"$ at 0 (checking anchored isall) minlen 1 Guessing start of match in sv for REx "XXX \(" against "(1,2,3) XXX (1 +,2,3)" Found anchored substr "XXX (" at offset 8... Starting position does not contradict /^/m... Guessed: match at offset 8 Matching REx "XXX \(" against "XXX (1,2,3)" 8 <2,3) > <XXX (1,2,3> | 1:EXACT <XXX (>(4) 13 < XXX (> <1,2,3)> | 4:END(0) Match successful! Guessing start of match in sv for REx "(XXX [^,]+)," against "(1,2,3) +XXX ('1,2,3)" Found anchored substr "XXX " at offset 8... Found floating substr "," at offset 15... Starting position does not contradict /^/m... Guessed: match at offset 8 Matching REx "(XXX [^,]+)," against "XXX ('1,2,3)" 8 <2,3) > <XXX ('1,2,> | 1:OPEN1(3) 8 <2,3) > <XXX ('1,2,> | 3:EXACT <XXX >(5) 12 < XXX > <('1,2,3)> | 5:PLUS(17) ANYOF[\0-+\--\377][{unicode_all}] ca +n match 3 times out of 2147483647... 15 <XXX ('1> <,2,3)> | 17: CLOSE1(19) 15 <XXX ('1> <,2,3)> | 19: EXACT <,>(21) 16 <XXX ('1,> <2,3)> | 21: END(0) Match successful! Matching REx "(XXX [^,]+)," against "2,3)" String too short [regexec_flags]... Match failed Guessing start of match in sv for REx ";" against "(1,2,3) XXX ('1';'2 +,3)" Found anchored substr ";" at offset 16... Starting position does not contradict /^/m... Guessed: match at offset 16 Matching REx ";" against ";'2,3)" 16 <X ('1'> <;'2,3)> | 1:EXACT <;>(3) 17 <X ('1';> <'2,3)> | 3:END(0) Match successful! Matching REx ";" against "'2,3)" Guessing start of match in sv for REx ";" against "'2,3)" Did not find anchored substr ";"... Match rejected by optimizer Not present... Match failed Guessing start of match in sv for REx "\)$" against "(1,2,3) XXX ('1', +'2,3)" Found anchored substr ")"$ at offset 21... Starting position does not contradict /^/m... Guessed: match at offset 21 Matching REx "\)$" against ")" 21 <X ('1','2,3> <)> | 1:EXACT <)>(3) 22 <X ('1','2,3)> <> | 3:EOL(4) 22 <X ('1','2,3)> <> | 4:END(0) Match successful! (1,2,3) XXX ('1','2,3') Freeing REx: "XXX \(" Freeing REx: "(XXX [^,]+)," Freeing REx: ";" Freeing REx: "\)$"
Basically the pattern you're matching only occurs one time.

In reply to Re: Need help with substitue /g by Anonymous Monk
in thread Need help with substitue /g by stephanm

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.