in reply to Delete all hash keys except for n of them

I've marked the important part below. Basically, each key => value pair is passed to @arr as two items, then %hash is redefined as the first 10 items (5 key => value pairs) of @arr.
use strict; my %hash; while (<DATA>) { chomp; split(/ => /); $hash{$_[0]} = $_[1]; } ###### my @arr = (%hash); %hash = splice(@arr,0,10); ###### for (keys %hash) { print "$_ => $hash{$_}\n"; } __DATA__ a => 1 b => 2 c => 3 d => 4 e => 5 f => 6 g => 7