I have not seen this before, and have used expect a lot. Could you post more of your code (the parts that generate the output, and buid $exp) so I can see if it is the way $exp was formed or the commands were run that is causing this. Also a raw dump of the $exp->log_file written to a file with the portion that you show uncorrectly formatted would be helpful.