We prove existence and regularity of optimal shapes for the problem
min{P(Ω)+G(Ω): Ω⊂D, |Ω|=m},
where P denotes the perimeter, |⋅| is the volume, and the functional G is either one of the following: extless{}ul extgreater{} extless{}li extgreater{} the Dirichlet energy E_f, with respect to a (possibly sign-changing) function f∈Lp; extless{}/li extgreater{} extless{}li extgreater{}a spectral functional of the form F(λ_1,...,λ_k), where λ_k is the kth eigenvalue of the Dirichlet Laplacian and F:Rk→R is Lipschitz continuous and increasing in each variable. extless{}/li extgreater{} extless{}/ul extgreater{}The domain D is the whole space Rd or a bounded domain. We also give general assumptions on the functional G so that the result remains valid.