Replace sed madness with beautiful Perl.