if ( $string =~ /[0-9a-fA-F]+/ ) { # valid number } else { # not valid number }