http://www.perlmonks.org?node_id=344475


in reply to newline behavior in Regular Expression

Works fine for me. The part of your regex that actually excludes the newline(s) is the ^ and $ anchors, not the .*?. But what you have works fine. $X correctly winds up being 0 or 1.