improving perl script