I find it ironic that you would ask us to write a solution for you rather than ask for assistance gaining a better understanding, and then in the same thread blame the "poor teaching system" for your not knowing how to do it. Decide now if you'll be the student who digs in and learns how to learn, or the student that gets weeded out after the 2nd semester (or the 2nd week on the job).
Get familiar with the Perl documentation. perlintro is a good place to start, and contains 99% of what you need to accomplish the task you've been assigned. Reading through it will take an hour. Absorbing it will take a little more in-depth study. That should put you back on the path of the student who learns how to learn (and consequently goes much farther than those who just want to get through the course).