I have a millions of pairs of string of same length which I want to compare and find the position where it has mismatches.
For example for each $str1 a
You're making 2 calls to substr for each character comparison which is probably what's slowing you down.
A few optimizations I would make
@source = split //,$str_source #split first rather than substr
@base = split //, $str_base
for $i (0 .. length($str_source)) {
$mism_pos{$1} = 1 if ($source[$i] ne $base); #hashing is faster than array push
}
return keys $mism_pos