in reply to regex for a socket stream

That's not easily done with a regex, I'd recommend Parse::RecDescent to whip up a quick parser.