- experiment with http://docs.php.net/manual/en/book.ds.php to improve performance. It has polyfil - iterators in Stream - generate regex - look at https://github.com/jubianchi/ppc - separate StringStream and MBStringStream - benchmark stream methods individually - more generally, benchmarking at the lowest levels first - use try for backtracking?