in reply to removing repeats
use strict; use warnings; my $strng = "hello hello the beatle said said to his fans"; my @words = $strng =~ /\G(\w+ ?)\1*/g; print join "*", @words; # hello *the *beatle *said *to *his *fans [download]