use warnings; use strict; while () { chomp; my $first = $_; my $second = ; last if ! defined $second; chomp $second; (print "Degenerate case: $first, $second\n"), next if length ($first) == 1 or length ($second) == 1; my $overlap = 0; while ($overlap < length $first) { my $tail = substr $first, -$overlap - 1; my $match = $tail ^ substr $second, 0, $overlap + 1; last if $overlap > 1 && $match =~ /^\0+$/; ++$overlap; } my $result = $first . substr $second, $overlap + 1; print "Merge $first and $second as $result\n"; } __DATA__ A ATG ATTTA TTTAA ATGTA ATGTA ATGATG ATGATG