while ( ... ) { ... } continue { # Reset the position of the regex match so that it will restart # just after the start of this match. This is done inside continue{} # to safeguard itself against a next() that someone else might # add later. pos() = $-[0] + 1; } #### while ( /($regex)/gx ) { push @substrings, { match => $1, pos => ( pos() - length $1 ), length => length $1,}; # Restart the checking at one character after the match started. pos() = $-[0] + 1; }