Peru doesn't have any formal dressing code. How one dresses is largely determined by the weather though in some parts locals have a unique dressing style, consider adjusting to their dressing code so that you can easily fit in. It's not necessary though.
Peru has extremely diverse climate regions from the pacific coastal region which is humid and got to areas around the Andes mountains which are cold and chilly while Amazonian regions are mostly wet.
Essential clothing pieces: In my opinion carrying jeans and a couple of t-shirts works well no matter which part of Peru you visit. Of course, carry some warm clothes if you visit the Andes mountains.
Tip:Avoid wearing Chulo hats in Lima if you want not to scream tourist. The wool caps are commonly worn in the Andes but not along the coast.
Standard Peruvian Dressing
In Lima, dressing is very liberal, just like in most European and American cities. You won't have a challenge figuring out what to dress or how to easily fit in among locals.
In Cusco and other Andean towns, women's dressing is consists of long colorful flowy skirts (polleras) and shoulder clothes known as Alicia. While you can wear this when roaming around in Cusco or other Andean towns, it's not appropriate attire if you'll be hiking in Macchu Picchu.
Men dressing code is quite casual and usually consists of jeans and ponchos.
Best time to visit Peru
Keep in mind that seasons in the southern hemisphere run opposite to those in the northern hemisphere. The best time to visit is from October -January, it's hot and most sites are accessible.
Don't go to Peru in February if you want to hike in Macchu Picchu. Mudslides are common in February and most hiking trails are closed.