in reply to update required for subroutine

I would recommend you read up on how Perl's array and hash structures work and on how to populate as well as iterate over them. Check here for a good start - perldsc

It also helps to initially draw your data structures on paper.