To do it perfectly you should learn perl and port your bash script:
In reply to Re: bash script to perl script by marto in thread bash script to perl script by pnkhakre