more improvements to perl script