foreach $replace (@substitutionlist) { ($oldline, $newline) = split(/\t/, $replace); $newline = s/\s/_SPACE_/g; #….more code here foreach $line (@array) { $count += s/\b$oldline\b/$spliced/eg for @array; #….more code here } } s/_SPACE_/ /g for @array;