Let G be a finite group and π an arbitrary set of primes. We investigate the structure of G when the lengths of the conjugacy classes of its π-elements are prime powers. Under this condition, we show that such lengths are either powers of just one prime or exactly {1,qa, rb}, with q and r two distinct primes lying in π and a, b > 0. In the first case, we obtain certain properties of the normal structure of G, and in the second one, we provide a characterisation of the structure of G.