my $string = " foo bar quz "; pos($string)=undef; # just to play it safe while ( $string =~ / \G \s* (foo|bar|quz) \s* /xgc) { print "<$1>\n"; } die "match failed at pos ".pos($string) unless pos($string)==length($string);