the following code compares the sequences $s and $t and calculates a 2-dim matrix containing the lengths of matching substrings at the position of the last matching characters. I don't know how to dereference in the nested foreach loop at the bottom in order to go through the matrix scalar by scalar.
$s = "evian-eauminerale";
$t = "borisvian-ecrivain";
foreach my $i (1..length($s)) {
foreach my $j (1..length($t)) {
if (substr($s, $i-1, 1) eq substr($t, $j-1, 1)) {
$M[$i][$j] = $M[$i-1][$j-1]+1;
$M[$i-1][$j-1] = 0;
}
}
}
foreach @array (@M) {
foreach $element (@array) {
print "$element ";
}
print "\n";
}