Perl rewrite