Convert perl script to bash

For a better compatibility