use strict; use warnings; my $str1 = "LTIEAVPSNAAEGKEVLLLVHNLPQDPRGYNWYKGETVDANRRIIGYVISNQQITPGPAYSNRETIYPNASLLMRNVTRNDTGSYTLQVIKLNLMSEEVTGQ-FSVHPETPKPSISSNNSNPVEDKDAVAFTCEPETQNTTYLWWVNGQSLPVSP"; my $str2 = "PTISPSYTYYRPGVNLSLSCHAASNPPAQYSWLIDGNIQQHTQE---------------------------LFISNITEKNSGLYTCQANNSASGHSRTTVKTITVSAELPKPSISSNNSKPVEDKDAVAFTCEPEAQNTTYLWWVNGQSLPVSP"; my %hash; my @a = split('',$str1); my @b = split('',$str2); my $a_index = 36; #Start counting at residue number my $b_index = 206; for my $i (0 .. $#b) { #Loop through arrays if ($b[$i] eq "-") { #Check for a gap in str2, if so increment a_index and go to the next residue $a_index++; next; } if ($a[$i] eq "-") { #Check for a gap in str1, if so store the gap in the hash without a residue #, increment b_index, and go to the next residue $hash{$b[$i].$b_index}=$a[$i]; $b_index++; next; } $hash{$b[$i].$b_index}=$a[$i].$a_index; #Else store residue pair in hash $b_index++; $a_index++; } print "value of N254 is $hash{'N254'}\n"; print "value of I255 is $hash{'I255'}\n"; print "value of K280 is $hash{'K280'}\n"; print "value of T281 is $hash{'T281'}\n"; print "value of I282 is $hash{'I282'}\n";