in reply to Looks like something is broken
So obviously the proportion of "0" characters is growing with each replacement in your loop.
Cheers Rolf (addicted to the Perl Programming Language and ☆☆☆☆ :) Wikisyntax for the Monastery