use strict; use warnings; my $source= '[TCG]GGGG[AT]'; # ambiguous my $target1 = 'AGGGGC'; # No of mismatch = 2 on position 1 and 6 my $target2 = 'TGGGGC'; # No of mismatch = 1 on position 6 only my @tar = split //, $target1; my @t = @tar; for my $i (1..($#t+1)) { my $a =''; if ($source !~ /^\[/) #not ambiguous { ($a) = $source =~ /^(.)/s; $source =~ s/^.//s; my $s = shift @tar; ($s eq $a) ? print "$s matches position $i in target\n" : print "$s not matches position $i in target\n"; } else #ambiguous { ($a) = $source =~ /^\[([^\]]*)/s; my @a = split //, $a; $source =~ s/^([^\]]*)\]//s; my $s = shift @tar; (my @m = grep /$s/, @a) ? print "[@a] matches position $i in target\n" : print "[@a] not matches position $i in target\n"; } }