for my $i (0 .. length($str1)) { if (substr($str1, $i, 1) ne substr($str2, $i, 1)) { $val++; } }