import hashlib


def generate_custom_objectid(s, l):
    """
    Generate a custom hex l-length ObjectId for MongoDB using md5 algorithm:

    Examples:
    >>> generate_custom_objectid('a013d9d4c046102a7849a8b3a56eee06a37769d4', 24)
    "58da1fe0b336eafd3590eea7"
    """
    string_to_bytes = bytearray(s, "ASCII")
    hashed_object = hashlib.md5(string_to_bytes)
    hexdig = hashed_object.hexdigest()[:l]
    return hexdig