in reply to adding a return to a file

Read perlintro. Start to learn to program. Write a program that solves your problem.

Since you didn't provide any sample input and output, and haven't shown us what you have tried and where you problems are, that seems to be the best advice we can give you at the moment.