This paper presents a new method for solving a class of infinite horizon nonlinear optimal control problems. In this method, first the original optimal control problem is transformed into a nonlinear two-point boundary value problem (TPBVP) via the Pontryagin's maximum principle. Then, using the homotopy perturbation method and introducing a convex homotopy in topologic space, the nonlinear TPBVP is transformed into a sequence of linear time-invariant TPBVP's. By solving the presented linear TPBVP sequence in a recursive manner, the optimal control law is determined in the form of infinite series. Finally, in order to obtain an accurate enough suboptimal control law, an iterative algorithm with low computational complexity is introduced. An illustrative example demonstrates the simplicity and efficiency of the proposed method.