rewrite of perl