From my reply to a discussion in r/canon on Reddit.
I’ve had both lenses. The STM delivers good image quality, excellent IS, and is relatively compact. It also costs significantly less than the L. The real downside is the variable aperture with the relatively slow f7.1 at the long end, but that doesn’t mean it’s not capable of delivering very good images. It’ll make a decent travel lens, especially if you take along a fast prime for when you need something with a wider aperture.
The L, on the other hand, has higher build quality, including weather sealing. The image quality is sharper across the frame and throughout the focal range, but the STM is pretty good in that regard. There’s also less chromatic aberration with the L. The constant F4 aperture is it’s biggest strength, though this comes at the cost of more weight and of course more cost. The wider, constant aperture gives the L lens an advantage with portraiture and in some lower light situations, or when capturing action. That being said, f4 doesn’t make it a very fast lens, and low light will quickly force a higher ISO or longer shutter speeds.
I got the STM as part of the R6 kit, and I already had the L that I had been using with my RP and R. I liked the STM a lot on the RP because the size matched it well. Both the R and R6 have a more substantial grip, so the heavier L wasn’t an issue. I ended up selling both the STM and the RP.
Look up Gordon Laing’s review of the STM lens, with comparisons to the L. Without knowing more about how you intend to use the lens and your budget, it’s hard to recommend one over the other. The L is certainly the better lens, but if you’re on a budget, the cost can be a limiting factor. In that case, the STM might just be good enough.