in reply to regex for a socket stream

As far as I know, you can't match a regex on a filehandle -- you have to have the entire string ready at the time of match. The regex engine won't "ask for more data" to become available.

You could build a plain old DFA. A DFA implementation is really simple, but the painful part is building the transition table. A DFA is a very low-level machine, so you have to end up writing very low-level code for it. Plus, you generally read one character at a time, which isn't very efficient.

What would be nicer is to have a state machine that reads one token at a time. So you should look at a lexer. A lexer will take a data stream (filehandle), and tokenize is as it comes in. This has the advantage of still processing the data as soon as it's available, but the token processing being much higher-level than a character-by-character DFA. Look at Parse::Lex (documentation en francais) and Parse::Flex.

blokhead