my %hash2 = map { $_ => $hash1{$_} } grep { defined $hash1{$_} } @ary;