in reply to Looks like something is broken

Your condition if $chr means only "1" characters are replaced by either 0 or 1, because $chr=0 is false.

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