my @foo = sort (keys %data); while( $_ = shift @foo ) { print "while: $data{$_}\n"; }