in reply to how to combine?
This is the best thing Perl does, parse text file, understand it, and process it.
So show effort and let some one here help you debug. At this point, you showed absolutely no effort.