Assuming the strings have the same length.
#!/usr/bin/perl
# https://perlmonks.org/?node_id=1218306
use strict;
use warnings;
use Algorithm::Diff qw(traverse_balanced);
compare( 'TTTATTT', 'TTTTTTT' );
compare( 'TTTTTTT', 'TBTTTTT' );
sub compare
{
my (@from, @to);
print "compare '$_[0]' to '$_[1]', differences are";
traverse_balanced( [ @from = split //, $_[0] ], [ @to = split //, $_
+[1] ],
{
CHANGE => sub { print " '$from[$_[0]]'\@$_[0]->'$to[$_[1]]'\@$_[1]
+" },
} );
print "\n";
}
Outputs:
compare 'TTTATTT' to 'TTTTTTT', differences are 'A'@3->'T'@3
compare 'TTTTTTT' to 'TBTTTTT', differences are 'T'@1->'B'@1