|Pathologically Eclectic Rubbish Lister|
Welcome to the monastery.
"I am getting output as ..."
Please show actual output between <code>...</code> tags. That way we can see exactly what you're seeing.
Please also show expected output (again, between <code>...</code> tags). Then we can see the difference between what you got and what you were trying to get.
From what you've posted, if
but you actually wanted something like
then you'll need to dereference the $difference arrayref:
That possibly raises a few questions, most of which may be answered by "Perl references short introduction".
If you have further questions, please follow the guidelines in "How do I post a question effectively?". Also, using a logical indentation, will make your code more readable for both you and us: that equates to less errors by you and, for us, a greater inclination to actually read your code.