my @dna = split("","ATCTGCG"); my @comp = split("","TCTGCAA"); my %pairs = qw(A T T A G C C G); foreach (0..$#dna) { my $d = $dna[$_]; my $c = $comp[$_]; print "$_: $d - $c is a mispair\n" unless ($pairs{$d} eq $c); }