sub get_ids { my %hash; @hash{@{shift()}} = undef; print "key:$_\n" for keys %hash; return \%hash; } # Call it this way my $hashref = get_ids( [qw/id_one id_two id_three/] ); #### key:id_one key:id_three key:id_two