Yup, I did this for a month back in my student days - the ticket is called Inter-Rail if you buy it within Europe. I was incentivised to basically visit a different country every day because every night spent on a train was one you didn't have to pay for a hostel! Also, some places like Florence had a free campsite with wooden shelters, you just had to bring a sleeping bag, and the month's rail ticket included an overnight ferry from Italy to Greece. Happy days!