The lower-level loops are interrupted (that is, the loop is broken) when Perl detects that a repeated expression matched a zero-length substring. Thus: m{ (?: NON_ZERO_LENGTH | ZERO_LENGTH )* }x; is made equivalent to m{ (?: NON_ZERO_LENGTH )* | (?: ZERO_LENGTH )? }x;