sub hash_slice { my ($hr, @k) = @_; return map { $_ => $hr->{$_} } @k; } # or using a slice (might be more efficient, but doesn't read as nicely) sub hash_slice { my ($hr, @k) = @_; my %ret; @ret{@k} = @$hr{@k}; return %ret; } # use like this: %pets = hash_slice( \%hash, qw( dog cat ) );