Each square has exactly \frac{1}{4} of its perimeter as part of the line, and together these form the whole line. This means the total perimeter is 4 \times 24\text{cm} = 96\text{cm}.
Algebraically, the diagram on the left shows that the line has length a+b+c+d+e+f = 24\text{cm}. The total of the perimeters is then: