Why do these not behave identically?
perl -e '$x = "12aba34ba5"; $, = ", "; print split /[ab]/, $x;'
12, , , 34, , 5
perl -e '$x = "12aba34ba5"; $, = ", "; print split /(a|b)/, $x;'
12, a, , b, , a, 34, b, , a, 5
This is documented in perldoc split:
If the PATTERN contains parentheses, additional list elements are created from each matching substring in the delimiter.
You can use (?:a|b) if you don't want to make backreferences.
/[ab]/to be/([ab])/you'd get both the same results.