in reply to Validating Hex Numbers

In addition to using an anchored(!) regex — but otherwise much as you wrote; you can also use the tr operator, like this:
length $h && $h !~ tr/0-9A-Fa-f//c;
This tests if $h doesn't contain any characters it shouldn't contain, and additionally, if there are any characters at all.