Distance between line and point Using 2D cartesian co-ordinates:
$Point = (x, y)$
$Line = (x_1,y_1),(x_2,y_2)$
Here we are taking $(x_1,y_1)$ and $(x_2, y_2)$ as line segment ends, not points on the infinitely extended line between those points.  
How can we calculate, if the point is perpendicular to the line, the distance between the two?
 A: CASE 1 - "INFINITE" LINE
Suppose we are given a infinite line through two points: $P_1(x_1,y_1)$ and $P_2(x_2,y_2)$; the aim is to determine the the distance between a point $Q(x_0,y_0)$ and the infinite line $\vec{P_1P_2}$.
The equation of the line through $P_1(x_1,y_1)$ and $P_2(x_2,y_2)$ in the general implicit form 
$$Ax + By + C = 0$$ 
can be easlily found expanding the following:
$$(y-y_1)(x_2-x_1)+(x-x_1)(y_2-y_1)=0$$
Finally the distance between the point $(x_0,y_0)$ and the line $Ax + By + C = 0$ is given by:
$$\text{Distance QP} = \frac{\left | Ax_{0} + By_{0} + C\right |}{\sqrt{A^2 + B^2} }$$
NOTE
It is meaningless define a “point perpendicular to a line”.
What is true is that the minimum distance between the point Q and a point P on the line is attained at $P$ such that the line $\vec{QP}$ is perpendicular to the line $\vec{P_1P_2}$.
CASE 2 - "FINITE" LINE
Suppose we are given a finite line between two points: $P_1(x_1,y_1)$ and $P_2(x_2,y_2)$ and the aim is to determine the the distance between a point $Q(x_0,y_0)$ and the line $\vec{P_1P_2}$.
In the simple case of 2D cartesian coordinates you can proceed firstly to draw a graph of the line $\vec{P_1P_2}$ and the point $Q(x_0,y_0)$ in order to verify whether or not the pependicular line from $Q$ to $\vec{P_1P_2}$ lies internally to $\vec{P_1P_2}$.
If the pependicular line from $Q$ to $\vec{P_1P_2}$ lies internally to $\vec{P_1P_2}$ you can determine the distance $QP$ as for the CASE 1.
If the pependicular line from $Q$ to $\vec{P_1P_2}$ lies externally to $\vec{P_1P_2}$ you can determine the distance $QP$ as:
$$QP=Minimum(QP_1,QP_2)$$
where (by Phytagorean Theorem):
$$QP_1= \sqrt{(x_1-x_0)^2+(y_1-y_0)^2}$$
$$QP_2= \sqrt{(x_2-x_0)^2+(y_2-y_0)^2}$$
NOTE
It would be possible solve the problem without any graphing in a pure algebric way but for this simple case it is not necessary.
A: the slope of your line lets say $l$ is given by $$m_1=\frac{y_2-y_1}{x_2-x_1}$$
and then we have
$$y=\frac{y_2-y_1}{x_2-x_1}x+n$$ with $$P(x_1,y_1)$$ we get $n$; the line perpendicular to the given line has the slope $$m_2=-\frac{1}{m_1}$$
Can you proceed?
