We show both numerically and experimentally that dispersion management can be realized by manipulating the dispersion of a filter in a passively mode-locked fibre laser. A programmable filter the dispersion of which can be software configured is employed in the laser. Solitons, stretched-pulses, and dissipative solitons can be targeted reliably by controlling the filter transmission function only, while the length of fibres is fixed in the laser. This technique shows remarkable advantages in controlling operation regimes in ultrafast fibre lasers, in contrast to the traditional technique in which dispersion management is achieved by optimizing the relative length of fibres with opposite-sign dispersion. Our versatile ultrafast fibre laser will be attractive for applications requiring different pulse profiles such as in optical signal processing and optical communications.