How do I substitute overlapping matches with a Perl regex?
问题 I want to find all occurences of "BBB" in a string and substitute them with "D" . For example, I have "ABBBBC" and want to produce "ADBC" and "ABDC" . (First substitute the first BBB , and then substitute the other BBB ). Is there a nice way to do this in Perl? $str = "ABBBBC"; for ( $str =~ m/B(?=BB)/g ) { # I match both the BBBs here, but how to substitute the relevant part? } I want to get this array: ('ADBC', 'ABDC') , which comes from changing either of the BBB s to a D . The string