An algorithm is presented that identifies major confinement regimes on-line during a plasma discharge in the Tokamak ASDEX Upgrade. Apart from the ohmically heated regime with no additional heating power, low and high radiative L and H regimes are distinguished. The algorithm was successfully implemented in the ASDEX Upgrade discharge control system, allowing a dynamic control of the plasma discharge. In a first application, the control system recognized the falling back of the plasma from a high confinement regime to a low confinement regime and reacted accordingly, avoiding a disruption and enhancing the plasma performance by recovering the high confinement regime.