#!/usr/bin/perl use warnings; $string="ATATGCGCAT"; ########################################### # Output to a TEXT File: ########################################### $output="Results .txt"; open (my $fh,">",$output) or die"Cannot open file '$output'.\n"; ##################################### # To break into 4-letter fragments: ##################################### while ($string=~ /(.{4}?)/ig) {$four=$&; @sw=$four=~ /[ATGC]{1}/igs; foreach my $single (@sw) { #################################################### # To extract single letter & append perd to single: #################################################### $perd="%d"; $mod_four=$single.$perd; # concatenation push @new_four,$mod_four; $new_four = join ('',@new_four); # To produce all possible combinations without changing positions: for $a (1 .. 2) { # a has 2 levels: for $t (1 .. 2) { # t has 2 levels: for $g (1 .. 2) { # g has 2 levels: for $c (1 .. 2) { # c has 2 levels: $combi=sprintf($new_four,$a,$t,$g,$c,3-$a,3-$t,3-$g,3-$c); print"~$combi\n"; print $fh "~$combi\n"; } } } } } # 2nd foreach closes: } # 1st while closes: print"~"; print"\n"; print $fh "~"; print $fh "\n"; close $output; exit;