use Algorithm::Diff qw(LCS); @seq1 = qw(a b c d f g h j q z); @seq2 = qw(a b c d e f g i j k r x y z); @lcs = LCS(\@seq1, \@seq2);