If you want them separate then remove the g modifier.
$_="a1 a2 a3"; while(?a(\d)?){ print $1; } while(?a(\d)?){ print $1; } __END__ 11
Updated to add in the snippet.
In reply to Re^3: Bizarreness in ?PATTERN? and g
by Mr. Muskrat
in thread Bizarreness in ?PATTERN? and g
by BUU
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |