I'm not sure I understand the question. Are you asking: "Because there is a space in the value of $ip_query, it should not match $regex, but the test shows that it does match. Why is that?"
If so, it's interesting that if I take (?: $RE{net}{IPv6} ) | out of the code, it behaves as expected -- that is, the value of $ip_query does not match $regex, when $regex is just (?: [0-9a-f:%]+)
Also interesting: when $regex is just (?: $RE{net}{IPv6} ) the string does not match, as expected -- that is, the test passes.
Looks like you need a set of parens that surrounds the conjunction alternation:
my $regex = qr/\A
(
(?: $RE{net}{IPv6} ) | # A full IPv6 address
(?: [0-9a-f:%]+ ) # A portion of an IPv6 address with SQL % wi
+ldcards
)
\Z/imsx;
|