for my $i (0 .. $bound) { my $substr1 = substr($str1, ($i * $step), $step); my $substr2 = substr($str2, ($i * $step), $step); if ($substr1 ne $substr2) { for my $j (0 .. ($step - 1)) { if (substr($substr1, $j, 1) ne substr($substr2, $j, 1)) { $val++; } } } }