How to move line along with mouse but in perpendicular direction

I have drawn polyshape geometry using lines. I want to move each line along mouse but in perpendicular direction. If line is parallel to x or y axis we can change x or y value according to that but if line is not parallel to x or y axis how to move that line in the perpendicular direction please. I am not getting any solution. So how to do that? Please find below image to the reffernce
15743859283738071385536174493868