In this study, by means of homotopy perturbation method (HPM) an approximate analytical solution of the magnetohydrodynamic (MHD) boundary layer flow of an upper-convected Maxwell (UCM) fluid over a porous stretching sheet is obtained. The main feature of the HPM is that it deforms a difficult problem into a set of problems which are easier to solve. HPM produces analytical expressions for the solution of nonlinear differential equations. The obtained analytic solution is in the form of an infinite power series. In this work, the analytical solution obtained by using only two terms from HPM solution. The results reveal that the proposed method is very effective and simple and can be applied to other nonlinear problems. Also it is shown that this method coincides with homotopy analysis method (HAM) for the studied problem. (C) 2010 Elsevier Ltd. All rights reserved.