Find all the pairs of positive integers $(x,y)$ such that $x\leq y$ and \[\frac{(x+y)(xy-1)}{xy+1}=p,\]where $p$ is a prime number.
1. Given the equation:
   \[
   \frac{(x+y)(xy-1)}{xy+1} = p,
   \]
   where \( p \) is a prime number, we start by analyzing the divisibility condition. We need \( xy + 1 \) to divide \( (x+y)(xy-1) \).

2. We can rewrite the condition as:
   \[
   xy + 1 \mid (x+y)(xy-1).
   \]
   Expanding the right-hand side, we get:
   \[
   (x+y)(xy-1) = (x+y)xy - (x+y) = x^2y + xy^2 - x - y.
   \]

3. We need \( xy + 1 \) to divide \( x^2y + xy^2 - x - y \). Notice that:
   \[
   (x+y)(xy+1) = x^2y + xy^2 + x + y.
   \]
   Therefore,
   \[
   (x+y)(xy+1) - (x+y)(xy-1) = 2(x+y).
   \]
   This implies:
   \[
   xy + 1 \mid 2(x+y).
   \]

4. From the divisibility condition \( xy + 1 \mid 2(x+y) \), we have:
   \[
   xy + 1 \leq 2(x+y).
   \]
   Rearranging this inequality, we get:
   \[
   xy + 1 \leq 2x + 2y.
   \]
   Subtracting \( 2x + 2y \) from both sides, we obtain:
   \[
   xy - 2x - 2y \leq -1.
   \]
   Adding 4 to both sides, we get:
   \[
   (x-2)(y-2) \leq 3.
   \]

5. We now consider the possible values of \( (x-2)(y-2) \) that satisfy the inequality \( (x-2)(y-2) \leq 3 \):
   - If \( x-2 = 0 \), then \( x = 2 \) and \( y-2 \leq 3 \), so \( y \leq 5 \).
   - If \( x-2 = 1 \), then \( x = 3 \) and \( y-2 \leq 3 \), so \( y \leq 5 \).
   - If \( x-2 = 2 \), then \( x = 4 \) and \( y-2 \leq 1 \), so \( y \leq 3 \).
   - If \( x-2 = 3 \), then \( x = 5 \) and \( y-2 \leq 1 \), so \( y \leq 3 \).

6. We now check the possible pairs \( (x, y) \):
   - For \( x = 2 \):
     - \( y = 3, 4, 5 \).
   - For \( x = 3 \):
     - \( y = 3, 4, 5 \).
   - For \( x = 4 \):
     - \( y = 3 \).
   - For \( x = 5 \):
     - \( y = 3 \).

7. We substitute these pairs into the original equation to check which ones satisfy the condition:
   - For \( (x, y) = (2, 3) \):
     \[
     \frac{(2+3)(2 \cdot 3 - 1)}{2 \cdot 3 + 1} = \frac{5 \cdot 5}{7} = \frac{25}{7} \quad \text{(not an integer)}.
     \]
   - For \( (x, y) = (2, 4) \):
     \[
     \frac{(2+4)(2 \cdot 4 - 1)}{2 \cdot 4 + 1} = \frac{6 \cdot 7}{9} = \frac{42}{9} \quad \text{(not an integer)}.
     \]
   - For \( (x, y) = (2, 5) \):
     \[
     \frac{(2+5)(2 \cdot 5 - 1)}{2 \cdot 5 + 1} = \frac{7 \cdot 9}{11} = \frac{63}{11} \quad \text{(not an integer)}.
     \]
   - For \( (x, y) = (3, 3) \):
     \[
     \frac{(3+3)(3 \cdot 3 - 1)}{3 \cdot 3 + 1} = \frac{6 \cdot 8}{10} = \frac{48}{10} \quad \text{(not an integer)}.
     \]
   - For \( (x, y) = (3, 4) \):
     \[
     \frac{(3+4)(3 \cdot 4 - 1)}{3 \cdot 4 + 1} = \frac{7 \cdot 11}{13} = \frac{77}{13} \quad \text{(not an integer)}.
     \]
   - For \( (x, y) = (3, 5) \):
     \[
     \frac{(3+5)(3 \cdot 5 - 1)}{3 \cdot 5 + 1} = \frac{8 \cdot 14}{16} = \frac{112}{16} = 7 \quad \text{(a prime number)}.
     \]
   - For \( (x, y) = (4, 3) \):
     \[
     \frac{(4+3)(4 \cdot 3 - 1)}{4 \cdot 3 + 1} = \frac{7 \cdot 11}{13} = \frac{77}{13} \quad \text{(not an integer)}.
     \]
   - For \( (x, y) = (5, 3) \):
     \[
     \frac{(5+3)(5 \cdot 3 - 1)}{5 \cdot 3 + 1} = \frac{8 \cdot 14}{16} = \frac{112}{16} = 7 \quad \text{(a prime number)}.
     \]

8. We also need to consider the cases when \( x = 1 \) or \( x = 2 \):
   - For \( x = 1 \):
     \[
     \frac{(1+y)(1 \cdot y - 1)}{1 \cdot y + 1} = \frac{(1+y)(y-1)}{y+1}.
     \]
     Simplifying, we get:
     \[
     \frac{y^2 - 1}{y+1} = y - 1.
     \]
     For this to be a prime number, \( y - 1 \) must be a prime number. Thus, \( y = p + 1 \) where \( p \) is a prime number.
   - For \( x = 2 \):
     \[
     2y + 1 \mid 2y + 4 \implies 2y + 1 \mid 3.
     \]
     This is impossible for \( y \geq x \).

Therefore, the solutions are \( (x, y) = (3, 5) \) and \( (x, y) = (1, p+1) \) for some prime \( p \).

The final answer is \( \boxed{ (x, y) = (3, 5) } \) and \((x, y) = (1, p+1)\) for some prime \( p \).