From the Super Mario Wiki
 Super Mario Galaxy
In Super Mario Galaxy, Stretch Plants appear in various galaxies, most notably the Good Egg Galaxy. If Mario or Luigi hit one with a spin, it will stretch in the opposite direction, hitting any enemy or obstacle in the way. If it fails to hit an obstacle or an enemy, it will come right back and hit the plumber, causing him to fall back and lose some Star Bits. If one is ground pounded or run over by an enemy such as a Boulder or a Chomp, it will become flattened and unusable for a short period of time.
Stretch Plants appear during the final fight with Bowser at Bowser's Galaxy Reactor. They are seen in the second phase of the final battle and are used as protection against Bowser's fireballs and are used to attack him.
 Super Mario Galaxy 2
Stretch Plants make an appearance yet again. However, they are uncommon, only appearing in the Sky Station Galaxy, Freezy Flake Galaxy and Battle Belt Galaxy. They keep their same appearance and use from the previous game. This time, they are used to defeat certain enemies such as Prickly Piranha Plants and Silver Chomps.
 Spiny Stretch Plant
Another kind of Stretch Plant appears as an enemy in the Honeybloom Galaxy during the events of the game. They are called Spiny Stretch Plants and they have red, retractable spikes. Unlike regular Stretch Plants, they are able to physically move themselves and will therefore try to hurt Mario or Luigi by extending their spiky ends at them. However, they cannot reach very far.