Sequence of replace in text files



I’m writing a “converter” for files which takes a file (say f1) and outputs a file (say g1) after having done a bunch of replace. Each file is likely to be reasonably short (< 1mb) but there are potentially many files to go over so processing speed is reasonably important.

I was wondering whether there are recommendations to improve something that effectively looks like:

s = readstring(f1)
for pp in pat_pairs
  s = replace(s, pp)
write(g1, s)

where pat_pairs is a list of regex-replacement pairs.