in reply to does code help regex match numeric ranges?

Is there a way to get the regex to fail in the cases where true is not printed? According to perlre it isn't possible:
(?{ code }) ... This zero-width assertion evaluates any embedded Perl code. It always +succeeds, and its code is not interpolated.

In other words you can't get the regex to fail using regex subs. You can obviously store the result of the sub in an var in the outer scope and evaluate it afterwards (just like moritz said). But the regex itself can't fail by design (when a code block is used).

If you don't want to use the regex solution, you might consider "hiding" it by using Regexp::Common. In your case probably Regexp::Common::net. (You are still using regex, but it's less obvious and less error prone).