C:\test>perl -M5.010 -w my $str = 'bxAybz'; while ( $str =~ / (?(?{1}) (b[xyz]) ) /gx ) { say 'yes'; say $1; } ^Z yes bx yes bz