you should use substr instead of vec to extract characters from a string:
sub common {
my ($a, $b)=@_;
return ($a, '', '') if $a eq $b;
for (my $i=0;;$i++) {
my $c=substr($a, $i, 1);
my $d=substr($b, $i, 1);
return (substr($a, 0, $i), $c, $d)
if $c ne $d;
}
}