#!/usr/bin/perl -w use strict; use warnings; my %test = ( a => 1, b => 2, c => 3, d => 4, ); foreach ( sort {$a cmp $b} keys %test ) { print "$_ -> $test{$_}\n"; }