Note that you replied to yourself instead of replying to me. Therefore, I did not notice your reply immediately.
Your code does not do what you claim. No arrays get merged when I run it. Please try to give more details: should the arrays be merged only if the last member is the same, or if any member is the same (i.e., should the script merge qw/a b key c/ with qw/x key y z/)? What would you do if more than one array from the second list could be merged into an array from the first one (i.e. both qw/car dog age/ and qw/train cat age/ in the second list)?