use strict; use warnings; my @targets = qw(AGGGGC TGGGGC); my @sources = (); chomp @sources; for my $source (@sources) { my @fields = grep length, split /(\[[^[\]]+\]|[^[\]]+)/, $source; my @cells = map {(index $_, '[') == 0 ? $_ : split ''} @fields; my $matchStr = join '', map {/\[/ ? "\x80" : $_} @fields; for my $target (@targets) { my @segments = grep length, split /(\x00+|.)/, $target ^ $matchStr; my $index = 0; for my $field (@segments) { next if length ($field) > 1 or $field eq "\x00"; # Only here for an ambiguous char my $str = $cells[$index]; my $chr = substr $target, $index, 1; next if $chr =~ /$str/; print "Mismatch at index $index in $source against $target\n"; } continue { $index += length $field; } } } __DATA__ [TCG]GGGG[AT] TGGGGT [AC][TCG]GGG[AT] #### Mismatch at index 0 in [TCG]GGGG[AT] against AGGGGC Mismatch at index 5 in [TCG]GGGG[AT] against AGGGGC Mismatch at index 5 in [TCG]GGGG[AT] against TGGGGC Mismatch at index 0 in TGGGGT against AGGGGC Mismatch at index 5 in TGGGGT against AGGGGC Mismatch at index 5 in TGGGGT against TGGGGC Mismatch at index 5 in [AC][TCG]GGG[AT] against AGGGGC Mismatch at index 0 in [AC][TCG]GGG[AT] against TGGGGC Mismatch at index 5 in [AC][TCG]GGG[AT] against TGGGGC