use strict; my @genes; my $screen = "ATCGATCGXXXXXATCGATXXXACTGCTACGGTACXXXAATTATXGCGCGXXT"; while ($screen =~ /(^|(?<=X))([^X]+)/g) { print "Gene $2 found at position ", length($`), "\n"; }