The kid cut out of grid paper with the side of the cell $1$ rectangle along the grid  lines and calculated its area and perimeter. Carlson snatched his scissors and cut out of this rectangle along the lines of the grid a square adjacent to the boundary of the rectangle.
- My rectangle ... - kid sobbed. - There is something strange about this figure!
- Nonsense, do not mention it -  Carlson said - waving his hand carelessly. - Here you see, in this figure the perimeter is the same as the area of ​​the rectangle was, and the area is the same as was the perimeter!
What size square did Carlson cut out?

Let's denote the sides of the original rectangle as \(a\) and \(b\), and the side length of the square that Carlson cut out as \(x\).

1. **Calculate the area and perimeter of the original rectangle:**
   - The area of the original rectangle is \(ab\).
   - The perimeter of the original rectangle is \(2(a + b)\).

2. **Calculate the area and perimeter of the new figure after cutting out the square:**
   - The area of the new figure is the area of the original rectangle minus the area of the square: \(ab - x^2\).
   - The perimeter of the new figure is the perimeter of the original rectangle plus the perimeter of the square minus the part of the perimeter that is shared with the rectangle. Since the square shares one side with the rectangle, the perimeter of the new figure is \(2(a + b) + 2x\).

3. **Set up the equations based on the given conditions:**
   - The perimeter of the new figure is equal to the area of the original rectangle:
     \[
     2(a + b) + 2x = ab
     \]
   - The area of the new figure is equal to the perimeter of the original rectangle:
     \[
     ab - x^2 = 2(a + b)
     \]

4. **Solve the system of equations:**
   - From the first equation:
     \[
     2(a + b) + 2x = ab \implies ab = 2(a + b) + 2x
     \]
   - From the second equation:
     \[
     ab - x^2 = 2(a + b)
     \]

5. **Combine the equations:**
   - Substitute \(ab\) from the first equation into the second equation:
     \[
     2(a + b) + 2x - x^2 = 2(a + b)
     \]
   - Simplify the equation:
     \[
     2x - x^2 = 0
     \]
   - Factor the equation:
     \[
     x(x - 2) = 0
     \]
   - Solve for \(x\):
     \[
     x = 0 \quad \text{or} \quad x = 2
     \]

6. **Determine the feasible solution:**
   - Since \(x = 0\) is not feasible (it implies no square was cut out), we have:
     \[
     x = 2
     \]

Therefore, the side length of the square that Carlson cut out is \(2\).

The final answer is \(\boxed{2}\)