in reply to Mapping array over a hash

map works like a function call. It returns the last thing executed in the block. And if that was the failure of a defined test, then it is a false value. The statement you wanted is:
my %hash2 = map {defined($hash1{$_}) ? ($_ => $hash1{$_}) : ()} @ary;
But note that I would avoid this with large arrays unless you are on 5.6.1 or better.