use strict; use warnings; use File::Find::Rule; my @files = File::Find::Rule->file ->name('complex.*') ->in ("/home"); my $new = 'replace'; open (REPLACE, "< $new") || die "could not open $new: $!"; ; my @new; while () { push @new, $_ =~ m/^(\S+\s+\S+\s+\S+)/; } close (REPLACE); my $count=0; foreach my $file (@files) { open (FH, "< $file") || die "could not open $file for input: $!";; open (OUT, "> output") || die "could not open 'output' for output: $!";; my $i=0; while () { $_ =~ s/^\S+\s+\S+\s+\S+/$new[$i++] /; print OUT $_; } close(FH) || die "could not close FH: $!"; ; close(OUT)|| die "could not close OUT: $!"; $count++; rename "output", "output$count"; }