my $regex = qr{ (? fo+ ) }msx; "barfooobar" =~ $regex; print "<",$+{foo},">\n"; # prints ""