use Regexp::Common qw /number/; while(){ chomp; print /\A$RE{num}{hex}\z/ ? 'YES' : 'NO '; print " $_\n"; } __DATA__ 12345 abc1234 foo123 ab123CD