in reply to perl file formatting

Any ideas please
  1. Write tests - lots of them. Dates are tricky, illogical things (months have varying numbers of days, timezones affect what the current date is, remember about leap years, etc.).
  2. Construct an algorithm to produce the desired output.
  3. Code up the algorithm.
  4. Run the tests and adjust the code and/or algorithm until they all pass.

Which specific part of all this are you having trouble with?