in reply to matching / splitting within a substitution

I can't explain why, but if you change from using the form
s{}[]gsex; ^^ to s{}{}gsex; ^^
your code works. I suspect this has something to do with how the substitution operator is parsing code within the /e block. Specifically, the quoted brackets in the split regex.