<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def replace_by_key(pif, key, subs, new_key=None, remove=False):
 """Replace values that match a key Deeply traverses the pif object, looking for `key` and replacing values in accordance with `subs`. If `new_key` is set, the replaced values are assigned to that key. If `remove` is `True`, the old `key` pairs are removed. """

    if not new_key:
        new_key = key
        remove = False
    orig = pif.as_dictionary()
    new  = _recurse_replace(orig, to_camel_case(key), to_camel_case(new_key), subs, remove)
    return pypif.pif.loads(json.dumps(new))