in reply to automatic endlines when saving txt file under windows?

Do you have binmode STDOUT in your script? If your script is being run under Windows, and you want to produce a windows-like file endings, you should not use binmode.

Regards, Dmitry.