When you are doing things like this, you should consider using a hash instead of an array:
my %hash = map { $_ => undef } @array;
# Add things to hash like this:
$hash{'a'} = undef;
$hash{'d'} = undef;
# Turn back into list with 'keys'
print join(',', sort keys %hash), "\n";