Blend if is a powerful tool in the layer properties in Photoshop (other software may have similar functionality – explore your documentation). Open the layer properties and you find an Advanced Blending block and Blend If block in the central column. You can use this to selectively define which parts of a layer are “blended” with underlying layers.
You can apply Blend-If to image layers. With Blend If can, for example, replace a blue sky with another layer without having to make complex selections or turn a green-screen transparent so you can see an underlying image where the green screen shows on the top layer.
You can apply Blend-If to adjustment layers so the adjustment selectively applies to parts of the underlying image (for example to darken a sky with an exposure adjustment that applies only for blue areas, or to bring up the shadows by applying an adjustment only over the darker areas.
Here is an example. Here I have an image of the Carillon in Canberra against a cloudless blue sky (layer 0). I have added a layer with a cloudy sky (layer 1). I opened the layer style dialog for Layer 1 (double click on the layer thumbnail). I have set the Blend-If to act on Blue colours, and on the underlying layer (the carillon) I have dragged the lower control triangle on the “underlying Layer” control to limit the range of blues where the blending occurs. OK, there is a wedge of blue sky showing through at the top. This can be easily fixed by duplicating a section of Layer 1 (clouds) that covers this blue – just one quick selection; we let Blend If do all the fiddly bits of selection around the trees and the structure.
Blend if can also be used when making more creative composite images and in applying textures selectively… have a play with the controls and see what they can do for you
Rather than more-inventing of the wheel, here are some resources on the web that give instructions on how to use Blend If: