use strict; use warnings; my $string = "CTCCGGATCTAT"; my $sets = length($string)/3; # we want to know how many sets of 3 there are my $unpacker = 'A3' x $sets; # create our unpack template my @dna = unpack($unpacker, $string); # create the array of sets my $counter = 0; # initialize the counter for my $set (@dna) { # for each $set in @dna do... my $check = substr($set, 2, 1); # get the 3rd char of the $set ++$counter if ($check =~ /[GC]/i); # increment the counter, ignore case } print "$counter/$sets was either C or G.\n"; # print results