So much of your code can be simplified by changing
while ($str =~ /([A-Z,0-9])/ig) {
to
while ($str =~ /(([A-Z,0-9])\2*)/ig) {
The posted code is beyond not elegant. It's in the realm of needless complexity.
Update: Forgot to mention:
Besides that, I don't know why you imposed a limit on which characters can be processed. The OP didn't mention anything about ignoring characters which are neither unaccented latin alpha, romanlatin? digits nor a comma. (Did you even mean to put that comma there?)
In reply to Re^2: Regex question
by ikegami
in thread Regex question
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |