in reply to How do you find duplicates in a string?

You can use regular expression capturing, and backreferences.

if( $string =~ m/ \b([[:alpha:]]+)\b # Match and capture word .*? # Skip what you don't need \b\1\b # Match the captured word /x ) { print $1, "\n"; }

Limitation: Words can contain only alpha characters. You could modify the expression: [[:alpha:]] so as to include what you might consider to be legal word characters, such as ' (apostrophe) and - (hyphen). I used the /x modifier to facilitate grouping the regular expression's sub-expressions into meaningful clusters so that it's easier to read.

Hope this helps!


Dave