in reply to Question on loops and variables

A sample of your data would be helpful in this case. I would also advise you to look into lexical filehandles as this in now pretty standard in modern perl. You could also look at using the autodie module to avoid some unneeded clutter.