in reply to Using negative lookahead

Perhaps you could use a full-on parser, such as Parse::RecDescent ...