my @all_names = qw/john andy bill andy john julia bill/; my %seen = (); my @names = grep { ! $seen{$_} ++ } @all_names; print join(' ', @names);