Note that in that thread, duelafnpointed out the modules Regexp::Trie and Regexp::Assemble, which might be helpful as well. Also, there's Regexp::Optimizer, which apparently (I haven't tried it out yet) has the ability to modify existing regexes, e.g. qr/foobar|fooxar|foozap/ becomes qr/foo(?:[bx]ar|zap)/.