in reply to Re^2: how to replace a matched pattern in a string with a different pattern of same length?
in thread how to replace a matched pattern in a string with a different pattern of same length?
$s = '00110011111110111111111111111110';; my $best = [0,0];; $+[0] - $-[0] > $best->[1] and $best = [ $-[0], $+[0] - $-[0] ] while $s =~ m[(1+)]g;; substr $s, $best->[0], $best->[1], '2'x$best->[1];; print $s;; 00110011111110222222222222222220
|
|---|