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


in reply to Re^2: Regex problems using '|'
in thread Regex problems using '|'

The regex engine starts at the start of the string, and tries to match the first alternative, here Remediation Report\n\n(.+?)\n. It doesn't match, so it tries the second alternative, ^(.+?)\n. That one matches, so it captures the first line in $1.

Without the alternation, the regex engine moves its starting position until it finds the substring Remediation Report.

(Actually it's much smarter than that; it searches for the constant substring with the same techniques that index uses, but from a users point of view that only matters when it comes to speed, not in terms of functionality).