use strict; use warnings; my %hash; while () { chomp; $hash{Makes}{$_} = undef; } print 'Before:', "\n"; print "$_\n" for keys %{ $hash{Makes} }; my $item = getCategoryItem( 'Makes', \%hash ); print "\n", 'Selected:', "\n", $item, "\n\n"; print 'After:', "\n"; print "$_\n" for keys %{ $hash{Makes} }; sub getCategoryItem { my ( $category, $hashRef ) = @_; my @items = keys %{ $hashRef->{$category} } or return undef; # undef is returned if no items my $item = $items[ rand $#items + 1 ]; delete $hashRef->{$category}{$item}; return $item; } __DATA__ Ford Chevrolet KIA