while ( my $html_file = $rule->match ) { # Change file in-place. local @ARGV = $html_file; local $^I = '.bak'; # Or '' to avoid making backups. while (<>) { ... # Keep (possibly edited) line print; } }