in reply to Shuffling cards

The program has to take in a string where b, i and o are functions and have coefficients and groupings such as b3(io) does b then io 3 times.
I forgot to mention in the other reply (and it seems to me to be an important bit, so that it deserves being pinpointed separately) that if grouping is involved, and if nested groupings are allowed, then basically you have to match balanced text which is not so trivial. In this case you may either adopt a ready made solution (e.g. Text::Balanced) or roll your own...