my @aminos = qw( A R N D C E Q G H I L K M F P S T W Y V ); # now A-R is the same as R-A in terms of interactions but if we # only use one we need a sort so use both, duplicate data but lose sort.... my @a_a; for my $a1(@aminos) { for my $a2(@aminos) { push @a_a, ["${a1}_${a2}", (join '', sort $a1,$a2)]; } } # now prepare our lookup table for interactions my %interactions; for my $a_ref( sort{ $a->[1] cmp $b->[1] }@a_a ) { $interactions{$a_ref->[0]} = rand; } my @chains = map{ [(@aminos)x25] } 0..5; my $interact; for my $ca_i( 0.. $#chains-1 ) { for my $cb_i( $ca_i+1 .. $#chains ) { print "Comparing chain $ca_i to $cb_i\n"; for my $res_a( @{$chains[$ca_i]} ) { for my $res_b( @{$chains[$cb_i]} ) { $interact = $res_a . '_' .$res_b; print "\t$interact => $interactions{$interact}\n"; } } } }