$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