rewrite of setup/fetch script in perl