in reply to removing repeats

You can use a regex to remove the duplicates:
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


holli, /regexed monk/