The question of optimal spanwise-periodic modification for the stabilisation of spanwise-invariant flows is addressed. A second-order sensitivity analysis is conducted for the linear temporal stability of parallel flows U-0 subject to small-amplitude spanwise-periodic modification epsilon U-1, epsilon << 1. It is known that spanwise-periodic flow modifications have a quadratic effect on stability properties, i.e. the first-order eigenvalue variation is zero, hence the need for a second-order analysis. A second-order sensitivity operator is computed from a one-dimensional calculation, which allows one to predict how eigenvalues are affected by any flow modification U-1, without actually solving for modified eigenvalues and eigenmodes. Comparisons with full two-dimensional stability calculations in a plane channel flow and in a mixing layer show excellent agreement. Next, optimisation is performed on the second-order sensitivity operator: for each eigenmode streamwise wavenumber alpha(0) and base flow modification spanwise wavenumber beta, the most stabilising/destabilising profiles U-1 are computed, together with lower/upper bounds for the variation in leading eigenvalue. These bounds increase like beta(-2) as beta goes to zero, thus yielding a large stabilising potential. However, three-dimensional modes with wavenumbers beta(0) = +/-beta, +/-beta/2 are destabilised, and therefore larger control wavenumbers should be preferred. The most stabilising U-1 optimised for the most unstable streamwise wavenumber alpha(0, max) has a stabilising effect on modes with other alpha(0) values too. Finally, the potential of transient growth to amplify perturbations and stabilise the flow is assessed with a combined optimisation. Assuming a separation of time scales between the fast unstable mode and the slow transient evolution of the optimal perturbations, combined optimal perturbations that achieve the best balance between transient linear amplification and stabilisation of the nominal shear flow are determined. In the mixing layer with beta <= 1.5, these combined optimal perturbations appear similar to transient growth-only optimal perturbations, and achieve a more efficient overall stabilisation than optimal spanwise-periodic and spanwise-invariant modifications computed for stabilisation only. These results are consistent with the efficiency of streak-based control strategies.