I was in Peru several months ago. I went from Arequipa to Ica. I just walked into the bus station in the morning and bought a ticket for that night. I bought a first class ticket and slept overnight on a big comfy chair. A simple dinner and breakfast was also served.
Buying a ticket there and then worked well for me, but I'm not sure if there's festivals happening when you're travelling.
I highly recommend the sand dunes of Huacachina