Lets call the perimeter P and the length of the rectangle l. The first figure is a square with side length 2x + 2 so P = 4(2x + 2) = 8x + 8. For the rectangle, P = 2l + 2(x + 3) = 2l + 2x + 6. These values both equal P so they must equal each other. 8x + 8 = 2l + 2x + 6. Now we have to solve for l.
8x + 8 = 2l + 2x + 6
8x + 2 = 2l + 2x
6x + 2 = 2l
3x + 1 = l