Rewrite inject_failures in Perl