my %hash = (auto=>1, bike=>1, foot=>1, motorbike=>1, boot=>1); for (sort {$a cmp $b } keys %hash){ print; }