my %temp; my @captured = grep { defined $temp{$_}++ } split / /, ; #### my %temp; my @captured = grep { ++$temp{$_} == 2 } split / /, ;