Thanks Mike, Francis and Martin for the quick replies! My mistake was using readlines() to read the text file, instead of read(). (I should have posted a snippet of code in the first place and probably you all would have noticed that immediately). - Matt