use File::Find; my @new_list; find sub { push @new_list, $File::Find::name if --- some criterion here ---; }, @ARGV; @ARGV = @new_list; $^I = ".bak"; while (<>) { s/old/new/g; print; }