I have written a small illustration of what I meant. See the attached file.
combine.f90 (3.1 KB)
This can even be extended to full-scale expressions. And an alternative might be the package feq-parse, see Feq-parse v2.2.0 Release - Custom Function Support