in reply to regexp with mismatches

For the first question, use:
/ABC(?:DD.|D.D|.DD).E/; # Add /s if newline is acceptable near the +Ds

As for the generic case, you don't. Regexes aren't suitable for that. For particular cases, you may be able to get away with listing all possibilities, or by using (?{...}), but in a general case, you'd be using the wrong tool.