$ perl -MDP -wE'my%x;()="iowq john stepy andy anne alic bert stepy anne bert andy step alic andy" =~ m/(\w+)(?{$x{$^N}++})/g;DDumper\%x'