my @matches = 'aXaYaZ' =~ /(a[XYZ])/g; say "@matches"; --output:-- aX