my %hash = (one => 1, two => 1, three => 1); my @keep = qw( two three ); my %keep = map { $_ => 1 } @keep; $hash{$_} = 0 for grep !$keep{$_}, keys %hash;