in reply to Regular expression for hexadecimal number
does that. I'm using the named character class [[:xdigit:]] in preference to the equivalent [0-9A-Fa-f]./^[[:xdigit:]]+$/
Checking whether a number is in a specific range is usually quite hard to do with a regex. While your specific case is an exception (the range is all numbers with up to four digits, which can easily be checked with a regex) I wouldn't make use of that. Instead I'd use a numeric comparison which also works for other ranges:
There is no need to check for >= 0 because Perl treats hexadecimal as unsigned, so every valid hex string will be non-negative./[[:xdigit]]+/ and hex( $_) <= 0xFFFF;
Anno
Update: Trivial (=silly) mistake corrected.