#!/usr/bin/perl -w use strict; sub get_ids { my $hashref = shift; print map {"$_\n"} keys %$hashref; # or, depending on your tastes # print "$_\n" for keys %$hashref; } get_ids( {map {$_,1} qw(one two three)} );