def replace_in_testbenches(
    testbenches, search_str, replace, include_langs=None, exclude_langs=None
):
    """
    In a testbench, replace a string with another string.

    Args:
        testbenches (str or dict): The testbench to replace text in. This may be
            a string representing a single testbench or a dictionary where
            different testbenches are indexed by language
        search_str (str): String to search for
        replace (str-like): Converted to string and used to replace search_str
        include_langs (iterable, optional): Iterable of a subset of languages to
            perform the replacement. Defaults to None.
        exclude_langs (iterable, optional): Iterable of a subset of languages to
            exclude from replacement. Defaults to None.

    Returns:
        str or dict: The modified testbench. Same type as testbenches
    """
    if isinstance(testbenches, str):
        testbenches = testbenches.replace(search_str, str(replace))
    else:
        for lang in [*testbenches]:
            if include_langs and lang not in include_langs:
                continue
            if exclude_langs and lang in exclude_langs:
                continue

            if isinstance(replace, dict):
                if lang in replace:
                    replace_str = str(replace[lang]).replace("$$lang", lang)
                else:
                    replace_str = ""
            else:
                replace_str = str(replace).replace("$$lang", lang)
            testbenches[lang] = testbenches[lang].replace(
                search_str, replace_str
            )
    return testbenches