Rewrite in perl