We report on real-time gas sensing with a terahertz quantum-cascade laser (QCL). The method is solely based on the modulation of the external cavity length, exploiting the intermediate optical feedback regime. While the QCL is operated in continuous-wave mode, optical feedback results in a change of the QCL frequency as well as its terminal voltage. The first effect is exploited to tune the lasing frequency across a molecular absorption line. The second effect is used for the detection of the self-mixing signal. This allows for fast measurement times on the order of 10 ms per spectrum and for real-time measurements of gas concentrations with a rate of 100 Hz. This technique is demonstrated with a mixture of D2O and CH3OD in an absorption cell.