use warnings; use strict; my $string = " foo bar quz "; print "String: '$string' length: ",length($string),"\n"; print "### Successful match with /c:\n"; pos($string)=undef; print "<$1>\n" while $string =~ / \G \s* (foo|bar|quz) \s* /xgc; print "pos: ",pos($string)//'undef',"\n"; print "### Failed match with /c:\n"; pos($string)=undef; print "<$1>\n" while $string =~ / \G \s* (foo|bar) \s* /xgc; print "pos: ",pos($string)//'undef',"\n"; print "### Successful match without /c:\n"; pos($string)=undef; print "<$1>\n" while $string =~ / \G \s* (foo|bar|quz) \s* /xg; print "pos: ",pos($string)//'undef',"\n"; print "### Failed match without /c:\n"; pos($string)=undef; print "<$1>\n" while $string =~ / \G \s* (foo|bar) \s* /xg; print "pos: ",pos($string)//'undef',"\n"; __END__ String: ' foo bar quz ' length: 13 ### Successful match with /c: pos: 13 ### Failed match with /c: pos: 9 ### Successful match without /c: pos: undef ### Failed match without /c: pos: undef