I think you've got the right idea using 1 while s///, because you're matching from inside out rather than left to right. Here's one way to do the whole substitution all at once:
This matches a parenthesized substring that does not itself contain any parenthesizes, and optionally a subsequent number, and replaces it with the substring, minus the parentheses, repeated the appropriate number of times.