Let's say I am measuring if X has a strong correlation to leading to Y.

I measure X, and I measure Y.

However, lets say that we have another variable Z: The higher the value of X, the higher the value of Z, but Z can also contribute to increasing Y.

How would I control for Z in this hypothetical study?

For example, lets say I am measuring concentration of a bacteria in the gut and seeing if it is related to a quantifiable scale in quality of life. Lets say that being overweight also directly increases the scores in the quantifiable scale.

Lets also say that the more concentration of bacteria in the gut you have, the more overweight you are as well. (So concentration of bacteria leads to both increases in the independent and dependent variable) How do I control for being overweight?

Thank you very much!