7) Aligning two protein sequences

From Biolecture.org

This one compares two sequence, which user input. But is not designed for global alignment. 

#!/usr/bin/perl
use strict;
use warnings;

  my $dna1 = <STDIN>;
  chomp($dna1);
   my @string1 = split ('', $dna1);
   my $len1 = length $dna1;

  my $dna2 = <STDIN>;
  chomp ($dna2);
  my @string2 = split ('', $dna2);
  my $len2 = length $dna2;

sub max {
    my ($max, @vars) = @_;
  for (@vars) {
     $max = $_ if $_ > $max;
    }
 return $max;
}

 my $stlen = max ($len1, $len2);

  foreach (my $i =0; $i < $stlen; $i++) {
      if ( $string1[$i] eq $string2[$i] ) {
     print " $string1[$i] = $string2[$i]\n";}
   else
        { print "$string1[$i] x $string2[$i]\n"; }
}
 

The output result sample is: 

MKRRRLLYYILEUGNMCG
KKKRRLLYVILEUGNNNG
 M x K
 K = K
 R x K
 R = R
 R = R
 L = L
 L = L
 Y = Y
 Y x V
 I = I
 L = L
 E = E
 U = U
 G = G
 N = N
 M x N
 C x N
 G = G