First combine the equations by replacing either l or w in the A=l*w equation. So I would solve for l in the other equation, l=6-w, then put that value of l into the other one as A=(6-w)*w. This is a quadratic; you can expand to get A=6w-w^2. Now you have to find the w value which gives you the max A (I’m assuming that’s what you wanted to find), and you can do this by finding the “axis of symmetry” of this quadratic function which is -b/(2a). a is -1 and b is 6, so w=3. If you solve for l you’d also get 3, since the max area for a given perimeter is a square.
I just noticed you said the answer is 2 and 4, which makes no sense unless you actually wanted to find something different.