Perhaps using IP addresses was not a good example, I'm trying to figure out how to parse a string which has repetitive data, so I can write the regex expression once and get multiple returns if they exist the same way your code got both IP addresses in one call.
Re^2: Using variable to hold regex expression
Replies are listed 'Best First'.
... how to parse a string which has repetitive data ...
As choroba pointed out, every (pattern) pair of parentheses in a regex captures something (even undef possibly) to its corresponding capture variable. One way to parse a string using nested regexes is avoid using a gazillion capturing groups. Use the non-capturing (?:pattern) instead for grouping. See perlre, perlrequick, perlretut. In the IP example (but this should generalize to any repetitive data you wish to extract):
Note that neither (?:pattern) nor the (?<!pattern) (?!pattern) look-around assertions capture. Indeed, nothing captures (to a capture variable) since data is extracted in list context directly to an array.