new perl script for mode calculation