Extension of Wertheim's thermodynamic perturbation theory and its combination with scaled particle theory is proposed and applied to study the liquid-gas phase behavior of polydisperse hard-sphere square-well chain fluid confined in the random porous media. Thermodynamic properties of the reference system, represented by the hard-sphere square-well fluid in the matrix, are calculated using corresponding extension of the second-order Barker-Henderson perturbation theory. We study effects of polydispersity and confinement on the phase behavior of the system. While polydispersity causes increase of the region of phase coexistence due to the critical temperature increase, confinement decreases the values of both critical temperature and critical density making the region of phase coexistence smaller. This effect is enhanced with the increase of the size ratio of the fluid and matrix particles. The increase of the average chain length at fixed values of polydispersity and matrix density shifts the critical point to a higher temperature and a slightly lower density.