in reply to Split operator in perl

Because your regex contains capturing parens, split will return both the separated bits and the captured separators:

print split ',', 'a,b,c';; a b c print split '(,)', 'a,b,c';; a , b , c

However, as you have a quantifier applied to the capturing parens, the regex will match multiple consecutive characters matching (a|b)+ but will only retain the last one captured. Hence although the regex matches & captures each of the four characters in 'abab', only the final 'b' will be retained and returned.

print 'abcd' =~ m[(.)+];; d

Putting that all together, and the delimiters used to split the string are as indicated by '[]': "[a]12cd[abab]"; but only the last single character of each delimiter is retained, hence:'(a)', '12cd', '(b)'


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.