You need to use string comparison in line 6: if ($key eq $thing) { However, it would be better to check existence of the array element as a hash key, exists $hash{$_} and push @new_array, $hash{$_} for @array; replaces the whole thing. That could be done with map and grep, too: my @new_array = map {$hash{$_}} grep {exists $hash{$_}} @array; or a slice with grep, my @new_array = @hash{ grep {exists $hash{$_}} @array };
After Compline,
Zaxo
In reply to Re: comparing array elements to hash keys
by Zaxo
in thread comparing array elements to hash keys
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |