use strict; use warnings; use Data::Dumper; use List::Util qw(min); my @tests = ( [qw{ABCGE ABCGE}], [qw{ABCGE FGCGB}], [qw{ABCGE JHAGT}], ); foreach my $arry_ref (@tests) { my ($str1,$str2) = @$arry_ref; # perhaps optional check to use shortest length my $len = min (length ($str1), length($str2)); my $c_delta = 0; my $i =0; while ($i < $len) { $c_delta++ if (substr($str1,$i,1) ne substr($str2,$i,1)); $i++; } print "$str1 $str2 $c_delta\n"; } __END__ ABCGE ABCGE 0 ABCGE FGCGB 3 ABCGE JHAGT 4