The secondary Oil recovery process is related with the Hele-Shaw immiscible displacement. A middle-layer (M.L.) is considered between the displacing fluid (water) and oil, containing a polymer solute, where the viscosity is an unknown parameter. We minimize the Saffman-Taylor instability, searching for the optimal viscosity in M.L. which gives a minimal growth constant of perturbations. We solve this optimization problem by using the methods of functional and numerical analysis for the Sturm-Liouville problems which govern the flow stability in such three-layer Hele-Shaw cells.The obtained formulas for the optimal viscosities are giving an almost neutral stability and are in accord with previous experimental and numerical results. We study the variable permeability and diffusion effects. We compute the necessary polymer amount and M.L. length for a given minimization of the fingering phenomenon. Some surfactant effects on rising gas-bubbles in capillary tubes are also studied.