#!/usr/bin/perl use strict; use warnings; # Create a test hash. my %test; $test{$_}="$_-$_" for ('aa' .. 'zz'); # Grab N keys. my $num_keys = 5; %test = (%test)[0..$num_keys*2-1]; # Display the result for (sort keys %test) { print "$_ = $test{$_}\n"; }