use strict; use warnings; my $string = "CTCCGGATCTAT"; my $counter = 0; $counter++ while $string =~ /..[GC]/gi; print "Found $counter occurences$/"; #### use strict; use warnings; my $string = "CTCCGGATCTAT"; my %flag = (C => 1, G => 1, A => 0, T => 0); my $counter = 0; $counter += $flag{$1} while $string =~ /..(.)/g; print "Found $counter occurences$/";