in reply to how can i replace a hash key with other hash value?

I don't really understand your question, but this:
%hash = { 'chapter' => ...};
is wrong. { } returns a reference to a hash, which is a scalar. Either use ( ) or change %hash to $hash.