You can just write the text to the file exactly as it was spoken now that you've added the 'n' flag to $read(), there's no need for that big chunk of code in blue.