line one line two line three line four #### line one line two line three line four #### foreach(@file) { for my $x (0..$#replace) { if($replace[$x] =~ /\\replace\t(.+?)\t(.+?)\n/g) { $_ =~ s/$1/$2/g; } print $_; } }