You can solve your immediate problem by using non-capturing parenthesis in the definitions of $ip4 and $ip6. Refer to the section (?pattern) in perlre
In reply to Re: Parenthesis grouping into regexes.
by BillKSmith
in thread Parenthesis grouping into regexes.
by aramisf
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |