use strict; use warnings; my @list = qw(A B C); my %hash; keys %hash = @list; for my $element ( qw(D A) ) { $hash{$element}++ unless exists $hash{$element}; } my @new_list = keys %hash; print "Keys are @new_list.\n"; # now insert @list @hash{@list} = (); @new_list = keys %hash; print "Keys are @new_list.\n";