You could get rid of the final bit of bookkeeping if you used `scanLeft` to build up all the prefixes and `foldLeft` to get the first match.

e.g.
```scala
  def assembleIdentifiers(ids: Seq[String]) = ids.mkString(".")

  def findFirstModule(names: String)(implicit mirror: JavaMirror): Option[ModuleSymbol] = {

    // Produce a sequence of all the identifier prefixes of the given name
    val identifierSeqs: Seq[Seq[String]] = splitIdentifiers(names).scanLeft(Seq.empty[String]) {
      case (prefix, elem) => prefix :+ elem
    }.drop(1)

    // Check if a given ident is a module
    def symbolForIdent(ident: String): Option[ModuleSymbol] = {
      try {
        val symbol = mirror.staticModule(ident)
        mirror.reflectModule(symbol).instance //if we can reflect a module it means we are module 
        Some(symbol)
      } catch {
        case _: reflect.internal.MissingRequirementError => None
        //FIXME: must be another way to check if a static modules exists than exceptions!?!
        case _: ClassNotFoundException => None
        //We tried to reflect a module but got a class cast exception (again, would be nice to do this differently)
      }
    }

    // Get the first matching module, if any
    identifierSeqs.foldLeft(Option.empty[ModuleSymbol]) {
      case (found@Some(_), _) => found
      case (None, identifier) => symbolForIdent(assembleIdentifiers(identifier))
    }
  }
```