my $string1 = 'ACTG'; my $string2 = 'TGAT'; my %corresponding = ('A' => 'T', 'T' => 'A', 'C' => 'G', 'G' => 'C'); my $count = 0; for (split '', $string1) { my $char = substr($string2, $count++, 1); if ($char ne $corresponding{$_}) { print "Position $count incorrect: 1: $_, 2: $char\n"; } }