#!/usr/bin/perl # http://perlmonks.org/?node_id=1144405 use Algorithm::Diff qw(traverse_sequences); use strict; use warnings; my $S=" MSATPLTQEQKKA"; my $T=" MNATLTQQTKA"; my @from = split //, shift // $S; my @to = split //, shift // $T; my $top = ''; my $bottom = ''; traverse_sequences( \@from, \@to, { MATCH => sub {$top .= $from[shift()]; $bottom .= $to[pop()]}, DISCARD_A => sub {$top .= $from[shift()]; $bottom .= ' '}, DISCARD_B => sub {$top .= ' '; $bottom .= $to[pop()]}, } ); print "$top\n$bottom\n";