#e.g. lemon-lemon apple-orange orange-lemon orange-apple #### my %hash = map { $keys[$_] => $values[$_] } 0.. $#keys; for (my $i=0; $i<@apple_ids; $i++) { while ( my ($key, $value) = each(%hash) ) { if ($apple_ids[$i] == $key) { print "apple"; } if ($apple_ids[$i] == $value) { print "apple"; } } } for (my $i=0; $i<@orange_ids; $i++) { while ( my ($key, $value) = each(%hash) ) { if ($orange_ids[$i] == $key) { print "orange"; } if ($orange_ids[$i] == $value) { print "orange"; } } } for (my $i=0; $i<@lemon_ids; $i++) { while ( my ($key, $value) = each(%hash) ) { if ($lemon_ids[$i] == $key) { print "lemon"; } if ($lemon_ids[$i] == $value) { print "lemon"; } } }