#!/usr/bin/perl # Libraries use strict; use warnings; # User-defined my $min = 2; my $max = 5; my %hash = ( a => 00, b => 01, c => 02, d => 03, e => 04, f => 05, g => 06 ); # Main program my @match = grep { $hash{$_} >= $min and $hash{$_} <= $max } keys %hash; my $rand = $match[rand @match]; printf "Random key = '%s', Value = '%s'\n", $rand, $hash{$rand};