Nissan help!

My 1997 Pathfinder has started doing something weird in the last month. When I drive around 40 - 50 mph and take my foot off the gas to coast, the RPMs drop down from above two to about 1.25. Then the RPMs shoot up to two and then down and up and down . . . until I press on the gas again. When this happens, I can feel it. It’s driving me crazy. Random, but could whatever this is be affecting my gas mileage?