If the number of fragments you want to combine isn't dynamic (i.e. it's always 2), just write the nested loops:
#!/usr/bin/perl
use warnings;
use strict;
my %fragments = ( 1 => { F => 'TTAAGTAGCATCGATTTATAGCATCGACTAGTAA',
R => 'TTACTAGTCGATGCTATAAATCGATGCTACTTAA',
},
2 => { F => 'TTAGCTACGATCAGCTACGATCGAGCGACTACGTAGCAA
+',
R => 'TTGCTACGTAGTCGCTCGATCGTAGCTGATCGTAGCTAA
+',
},
);
my %combinations;
for my $fragment (keys %fragments) {
for my $other_fragment (keys %fragments) {
next if $fragment eq $other_fragment;
for my $cognate (qw( F R )) {
for my $other_cognate (qw( F R )) {
$combinations{"$fragment$cognate$other_fragment$other_
+cognate"}
= $fragments{$fragment}{$cognate}
. $fragments{$other_fragment}{$other_cognate};
}
}
}
}
use Data::Dumper;
print Dumper(\%combinations);
This generates 8 entries, not four, as it creates 2F1F etc., too. You can modify the "next" condition to avoid it, i.e.
next if $fragment ge $other_fragment;
If you need to combine N fragments, see Algorithm::Loops.
($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord
}map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,