in reply to Need help with a script

Whenever I have a basic computing problem like this in Perl, the first place I look is this site's Q&A section. And sure enough, someone has asked this question and got an answer.