We calculate the torus partition sum of a general CFT2 with left and right moving conserved currents J and overline{J} , perturbed by a combination of the irrelevant operators Toverline{T},Joverline{T} and Toverline{J} . We use string theory techniques to write it as an integral transform of the partition sum of the unperturbed CFT with chemical potentials for the left and right moving conserved charges. The resulting expression transforms in the right way under the modular group, and reproduces the known spectrum of these models. We also derive a formula for the partition function of deformed CFT2 with non-vanishing chemical potentials.