use strict; use warnings; my $string = "aaaggctt"; my %hash = qw(a t g c c g t a); print "The DNA string is: \n"; print $string,"\n"; print "The reverse complement is: \n"; #One way to do it... 1st chunk.. for (my $i = length($string); $i>= 0 ; $i--){ for (keys %hash){ print substr($string, $i, 1) eq $_ ? $hash{$_} : ''; } } print "\n" #Expansion of the previous solution.. 2nd chunk.. for (my $i = length($string); $i>= 0 ; $i--){ for (keys %hash){ if(substr($string, $i, 1) eq $_ ){ print $hash{$_}; } } } #### $t1 = Benchmark->new; # First chunk from the code above $t2 = Benchmark->new; $t3 = Benchmark->new; # Second chunk from the code above $t4 = Benchmark->new; $td1 = timediff($t2-$t1); $td2 = timediff($t4-$t3); print timestr($td1),"\n",timestr($td2); ####