in reply to Tips on how to perform this substitution?

Here's another way to do it:

#!/usr/bin/env perl -l use strict; use warnings; my $string = '---BB--BBB---BBB---B-B---'; print $string; $string =~ y/B/M/; print $string; my @subs = qw{i o}; my $i = 1; $string =~ s/(-+)/$subs[$i ^= 1] x length $1/eg; print $string;

Output:

---BB--BBB---BBB---B-B--- ---MM--MMM---MMM---M-M--- iiiMMooMMMiiiMMMoooMiMooo

-- Ken