Concept:
For a thin convex lens,
\[
\frac{1}{f}=\frac{1}{v}-\frac{1}{u}
\]
and magnification is given by
\[
m=\left|\frac{v}{u}\right|
\]
A virtual image formed by a convex lens is erect and lies on the same side as the object, whereas a real image is formed on the opposite side of the lens.
Step 1: Write the object distances in the two cases.
Initially,
\[
u_1=-12\text{ cm}
\]
The object is moved 18 cm away from the lens.
Therefore,
\[
u_2=-(12+18)
\]
\[
u_2=-30\text{ cm}
\]
Step 2: Find magnification for the virtual image.
Using the lens formula,
\[
\frac{1}{f}=\frac{1}{v_1}+\frac{1}{12}
\]
Solving,
\[
v_1=\frac{12f}{12-f}
\]
Hence,
\[
m_1=\frac{v_1}{12}
\]
\[
m_1=\frac{f}{12-f}
\]
Step 3: Find magnification for the real image.
Similarly,
\[
\frac{1}{f}=\frac{1}{v_2}+\frac{1}{30}
\]
\[
v_2=\frac{30f}{30-f}
\]
Thus,
\[
m_2=\frac{v_2}{30}
\]
\[
m_2=\frac{f}{30-f}
\]
Step 4: Use the condition given in the question.
The magnification of the virtual image is five times the magnification of the real image.
\[
m_1=5m_2
\]
\[
\frac{f}{12-f}
=
5\left(\frac{f}{30-f}\right)
\]
Cancelling \(f\),
\[
30-f=5(12-f)
\]
\[
30-f=60-5f
\]
\[
4f=30
\]
\[
f=18\text{ cm}
\]
Step 5: State the answer.
\[
\boxed{f=18\text{ cm}}
\]