in reply to how to improve this script

I've been following all of your posted questions, and the threads they result in. You're doing yourself a disservice by coming here everytime you add a few lines and encounter another problem or have another question. You'll never strengthen your Perl-fu (or indeed, programming skills in general) if you don't try to solve these problems yourself.