pos
pos SCALAR
Returns the location in SCALAR where the last m//g search over SCALAR left off. It returns the offset of the character after the last one matched. (That is, it's equivalent to length($`) + length($&).) This is the offset where the next m//g search on that string will start. Remember that the offset of the beginning of the string is . For example:
$grafitto = "fee fie foe foo"; while ($grafitto =~ m/e/g) {
print pos $grafitto, "\n";
}
prints , , , and , the offsets of each of the characters following an "e". The pos function may be assigned a value to tell the next m//g where to start:
$grafitto = "fee fie foe foo"; pos $grafitto = 4; # Skip the fee, start at fie while ($grafitto =~ m/e/g) {
print pos $grafitto, "\n";
}
This prints only and . (Thank heaven.) The regular expression assertion, G, matches only at the location currently specified by pos for the string being searched.