$ perl -E 'say "0x47_not_hex" =~ /^0x/ ? "is hex" : "is NOT hex"' is hex $ perl -E 'say "0x47_not_hex" =~ /^0x[0-9a-fA-F]+$/ ? "is hex" : "is NOT hex"' is NOT hex