The R*-operation by Chetyrkin, Tkachov, and Smirnov is a generalisation ofthe BPHZ R-operation, which subtracts both ultraviolet and infrared divergencesof euclidean Feynman graphs with non-exceptional external momenta. It can beused to compute the divergent parts of such Feynman graphs from products ofsimpler Feynman graphs of lower loops. In this paper we extend the R*-operationto Feynman graphs with arbitrary numerators, including tensors. We also providea novel way of defining infrared counterterms which closely resembles thedefinition of its ultraviolet counterpart. We further express both infrared andultraviolet counterterms in terms of scaleless vacuum graphs with a logarithmicdegree of divergence. By exploiting symmetries, integrand and integralrelations, which the counterterms of scaleless vacuum graphs satisfy, we canvastly reduce their number and complexity. A FORM implementation of this methodwas used to compute the five loop beta function in QCD for a general gaugegroup. To illustrate the procedure, we compute the poles in the dimensionalregulator of all top-level propagator graphs at five loops in four dimensionalphi^3 theory.