use strict;
use warnings;
my %hash = (
one => 1,
two => 2,
four => 4,
);
my @required_keys = qw(two three four
); my %result_hash = map { $_ => $hash{$_} if (exists $hash{$_}) } @required_keys;
use Data::Dumper;
print 'Resulting hash: ' . Dumper
(\%result_hash);
dXNlIHN0cmljdDsKdXNlIHdhcm5pbmdzOwoKbXkgJWhhc2ggPSAoCiAgICBvbmUgPT4gMSwKICAgIHR3byA9PiAyLAogICAgZm91ciA9PiA0LAopOwoKbXkgQHJlcXVpcmVkX2tleXMgPSBxdyh0d28gdGhyZWUgZm91cik7Cm15ICVyZXN1bHRfaGFzaCA9IG1hcCB7ICRfID0+ICRoYXNoeyRffSBpZiAoZXhpc3RzICRoYXNoeyRffSkgfSBAcmVxdWlyZWRfa2V5czsKCnVzZSBEYXRhOjpEdW1wZXI7CnByaW50ICdSZXN1bHRpbmcgaGFzaDogJyAuIER1bXBlcihcJXJlc3VsdF9oYXNoKTsK