use warnings; use strict; my $str='XtestXYtest2'; my $BRK = qr(X|Y|^|$)i; my @pieces = $str =~ /($BRK+)(.+?(?=$BRK))/gsp; push @pieces,${^POSTMATCH} if ${^POSTMATCH}; print "INTENDED: These were the phrases (and breaks) extracted:\n",join("\n",@pieces),"\n-------\n"; $BRK = qr(^|X|Y|$)i; @pieces = $str =~ /($BRK+)(.+?(?=$BRK))/gsp; push @pieces,${^POSTMATCH} if ${^POSTMATCH}; print "WRONG: These were the phrases (and breaks) extracted:\n",join("\n",@pieces),"\n";