perl version of bash script. in development