foreach my $keys (keys(%hash)) { my $races = $hash{$keys}; # For easy access to @$races ... my $choice = "INVALID"; while (not ( $choice=~/^\d+$/ and defined $races->[$choice -1])){ print ($_ +1) . " . " . $races->[$_] . "\n" for 0..$#$races; print "\nGive me your choice..\n"; chomp ( $choice = ); } ....