use strict; my @genes; while ($screen =~ /([^X]+)/g) { push @genes, $1; print "$1 occurred at ", pos($screen) - length $1, $/; }