use warnings; use strict; use 5.010; my @arr = qw{ a a b b c c c }; my %hash; @hash{@arr} = undef; use Data::Dumper; say Dumper(\%hash); --output:-- $VAR1 = { 'c' => undef, 'a' => undef, 'b' => undef }; ----------- if (exists $hash{a} ) { say 'yes'; } else { say 'no'; } --output:-- yes ---------- for (keys %hash) { say; } --output:-- c a b