just adding an s modifier to each regex ought to do it: it'll then treat the whole thing as if it were one line (or, strictly, it'll treat line-endings as just another character), as the early parts of perlre will explain. I should have put that in, but your example was just one line so I didn't bother: