Variable stars in the globular cluster M5: application of the image subtraction method