A new method which is based on two transformations, called the HMDR and the FMDR transformation, is presented for solving the generalized eigensystem Ax=λBx, where A,B are real square matrices. To overcome difficulties arising in the presence of infinite eigenvalues with high-order Jordan block, we introduce a new procedure which could be used as "preprocessing" to deflate the infinite eigenvalue. This method initially reduces B to a diagonal matrix with nonnegative entries and deflates the infinite eigenvalues if necessary. Maintaining the diagonal form of the right-hand-side matrix, A-λB is first reduced to Hessenberg diagonal form and then in an iterative part to quasitriangular diagonal form. In computational work it shows higher efficiency than the QZ algorithm, and in stability it is analogous to the MDR algorithm. Our method is closely related to the QR algorithm in essence.