cleaned up perl script