in reply to how to replace a matched pattern in a string with a different pattern of same length?
perl -le '$_="00110011111110111111111111111110"; $m=( sort({length($b) +<=>length($a)} /(1+)/g ) )[0];s/$m/2 x length $m/e;print' [download]
Paul