<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _filter_file(src, dest, subst):
 """Copy src to dest doing substitutions on the fly. """

    substre = re.compile(r'\$(%s)' % '|'.join(subst.keys()))
    def repl(m):
        return subst[m.group(1)]
    with open(src, "rt") as sf, open(dest, "wt") as df:
        while True:
            l = sf.readline()
            if not l:
                break
            df.write(re.sub(substre, repl, l))