use strict; use warnings; my @changefile = ( '/export/home/test1:aaaa:bbbb', '/export/home/test2:kkkk:llll' ); foreach my $list(@changefile){ my @splitlist = split(/:/, $list); open(FILE, $splitlist[0]) or die "$!"; my @file = <FILE>; close(FILE); foreach my $line (@file) { $line =~ s/$splitlist[1]/$splitlist[2]/g; print "$line\n"; } open(FILE2, "> $splitlist[0]") or die "$!"; print "$splitlist[0]\n"; print @file; print FILE2 @file; close(FILE2); }