3.5. The Regexp Engine

Another area of the Perl source best avoided is the regular expression engine. This lives in re*.*. The regular expression matching engine is, roughly speaking, a state machine generator. Your match pattern is turned into a state machine made up of various match nodes - you can see these nodes in regcomp.sym. The compilation phase is handled by regcomp.c, and the state machine's execution is performed in regexec.c.

Did You Know?

The regular expression compiler and interpreter are actually switchable; it's possible to remove Perl's default regular expression engine and insert one's own custom engine. (This is done by changing the value of the global variables PL_regcompp and PL_regexecp to be function pointers to the required routines.) In fact, that's exactly what the re module does.