my %matches = map {$_ => 1} 17, 83, 114, 205, 407; while (my ($key, $value) = each %hash) { my @value_tokens = split /::/, $value; foreach my $value_token (@value_tokens) { if ($matches{$value_token}) { print "$key: $value\n"; $found = 1; last; ### break out of foreach } } ### end foreach if $found: next; } } ### end while