Let the side of the square be "x".

Let the width of the rectangle be "y".

The perimeter of the square is

The perimeter of the rectangle is

The perimeters are equal, so

The square area is

The rectangle area is

Then you can eliminate y and solve for x in the simultaneous equations..

or, as your title suggests, substituting for y and completing the square.