$ perl -le 'my @array = qw( foo bar bar baz); my @dups = do {my %h; grep $h{$_}++, @array}; print join( ", ", @dup );' $