my %hash = map {$numbers[$_] => $values[$_]} 0 .. $#numbers; # my @keys = keys %hash; # print @keys; foreach my $thing (@array) { # print $thing; if (exists ($hash{$thing})) { push @new_array, $thing; } } print @new_array;