use Algorithm::Diff qw(sdiff); use Data::Dumper; my $a=sdiff( [split(/\W+/,"the quick brown fox")], [split(/\W+/,"before the quick brown fox")] ); print Dumper($a); $VAR1 = [ [ '+', '', 'before' ], [ 'u', 'the', 'the' ], [ 'u', 'quick', 'quick' ], [ 'u', 'brown', 'brown' ], [ 'u', 'fox', 'fox' ] ];