I just want to say thank you to everyone for all of the information.
I changed the script as Ikegami suggested and not only works good but it made it more clear how Perl loops through the data .
It seems to me that the foreach statement only
process one line at a time as with each item withen the loop
and continues so until all lines in the orignal data file were processed.
I was confused because I thought it processed all the
lines for each item whiten the loop and only made one pass
I hope my though process is clear on this now so I can move on