use strict; use warnings; my %diags = ( "Meningitis" => \@array, "Encephalitis" => \@Encephalitis_77, # more of them here ); my $Search = qw( 6280 ); my $found_one = 0; for my $diag ( keys %diags ) { if( my @found = grep { $_ eq $Search } @{$diags{$diag}} ) { my $found = join ",", @found; print "Primary diagnosis: $diag, $found\n"; $found_one = 1; } } print "Sorry, \"$Search\" not found in diagnosis list\n" unless $found_one;