in reply to Regex help

I don't think there is any direct way of doing this with a regex as there is no way to do a capture of the encompassed string without advancing the position.

Thus, you have to reset the position (pos) to the end of the first bracketing word ($+[1]) after each match.

$s = 'The quick brown fox jumped over the other quick brown fox'; print $2 and pos($s) = $+[1] while $s =~ m[\b(\S+)\b(.+?)\b\1\b]g; brown fox jumped over the other fox jumped over the other quick jumped over the other quick brown

this includes the white space either end of the encompassed text. To avoid that change the regex to  m[\b(\S+)\b\s+(.+?)\s+\b\1\b]g.


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
Timing (and a little luck) are everything!