my %hash = (0 => 1, 5 => 1, 8 => 1, 15 => 1, 20 => 1); for my $i (0..30) { if ($hash{$i}) { print "I am number $i\n"; } }