The trick here is to be very careful reading the question and converting it into equations.
There are 2 unknowns: the length of the rectangle (call it x) and the side of the square (call it s).
The first sentence says 2(x+6) = 4s.
The next sentence says 6x = s2 - 16.
From the linear equation s = (1/2)(x+6)
Substitute this into the other equation: 6x = (1/4)(x2 + 12x + 36) - 16
Clear fractions and carefully collect terms: x2 - 12 - 28
This factors as (x+2)(x-14)
The root x = -2 makes no physical sense.
The other root x = 14 solves the problem because from s = (1/2)(x+6), s = 10
Now check that the 2 perimeters are the same and that the relationship between the 2 areas is correct.