Find all pairs $(p,n)$ so that $p$ is a prime number, $n$ is a positive integer and \[p^3-2p^2+p+1=3^n \] holds.
We are given the equation \( p^3 - 2p^2 + p + 1 = 3^n \) and need to find all pairs \((p, n)\) where \(p\) is a prime number and \(n\) is a positive integer.

1. **Case \( p = 2 \):**
   \[
   2^3 - 2 \cdot 2^2 + 2 + 1 = 8 - 8 + 2 + 1 = 3 = 3^1
   \]
   Thus, \( (p, n) = (2, 1) \) is a solution.

2. **Case \( p \neq 2 \):**
   We start by factoring the left-hand side:
   \[
   p^3 - 2p^2 + p + 1 = p(p-1)^2 + 1
   \]
   This gives us:
   \[
   p(p-1)^2 + 1 = 3^n
   \]
   Rearranging, we get:
   \[
   p(p-1)^2 = 3^n - 1
   \]
   Since \( p \) is a prime and \( p \neq 2 \), \( p \) is odd. Therefore, \( p-1 \) is even, and \( (p-1)^2 \) is divisible by 4. Hence, \( p(p-1)^2 \) is divisible by 4. This implies:
   \[
   4 \mid (3^n - 1)
   \]
   Since \( 3^n \equiv 1 \pmod{4} \) for even \( n \), \( n \) must be even. Let \( n = 2k \). Then:
   \[
   p(p-1)^2 = (3^k - 1)(3^k + 1)
   \]
   Since \( 3^k - 1 \) and \( 3^k + 1 \) are consecutive even numbers, one of them is divisible by 4, and the other is divisible by 2. 

3. **Case \( p \mid 3^k - 1 \):**
   Let \( 3^k - 1 = pr \) for some integer \( r \geq 2 \). Substituting back, we get:
   \[
   p(p-1)^2 = pr(pr + 2)
   \]
   Simplifying, we have:
   \[
   p^2 - (2 + r^2)p + (1 - 2r) = 0
   \]
   The discriminant of this quadratic equation in \( p \) must be a perfect square:
   \[
   D = (2 + r^2)^2 - 4(1 - 2r) = r^4 + 4r^2 + 8r
   \]
   We need \( D \) to be a perfect square. However:
   \[
   (r^2 + 3)^2 > D > (r^2 + 2)^2
   \]
   Thus, \( D \) cannot be a perfect square.

4. **Case \( p \mid 3^k + 1 \):**
   Let \( 3^k + 1 = pr \) for some integer \( r \geq 2 \). Substituting back, we get:
   \[
   p(p-1)^2 = pr(pr - 2)
   \]
   Simplifying, we have:
   \[
   p^2 - (2 + r^2)p + (1 + 2r) = 0
   \]
   The discriminant of this quadratic equation in \( p \) must be a perfect square:
   \[
   D = (2 + r^2)^2 - 4(1 + 2r) = r^4 + 4r^2 - 8r
   \]
   We need \( D \) to be a perfect square. Since \( r \geq 2 \):
   \[
   (r^2 + 2)^2 > D \geq (r^2)^2
   \]
   We have two options:
   \[
   D = (r^2 + 1)^2 \implies 2r^2 - 8r - 1 = 0 \implies r \not\in \mathbb{Z}
   \]
   \[
   D = r^4 \implies 4r(r-2) = 0 \implies r = 2
   \]
   If \( r = 2 \), then:
   \[
   3^k + 1 = 2p \quad \text{and} \quad 3^k - 1 = \frac{(p-1)^2}{2}
   \]
   Subtracting these equations:
   \[
   2 = 2p - \frac{(p-1)^2}{2}
   \]
   Solving for \( p \):
   \[
   4 = 4p - (p-1)^2 \implies 4 = 4p - (p^2 - 2p + 1) \implies 4 = 4p - p^2 + 2p - 1 \implies p^2 - 6p + 5 = 0
   \]
   Solving the quadratic equation:
   \[
   p = \frac{6 \pm \sqrt{36 - 20}}{2} = \frac{6 \pm \sqrt{16}}{2} = \frac{6 \pm 4}{2}
   \]
   Thus, \( p = 5 \) (since \( p = 1 \) is not a prime). Substituting back, we get:
   \[
   3^k + 1 = 2 \cdot 5 = 10 \implies 3^k = 9 \implies k = 2 \implies n = 4
   \]

So, the final solutions are:
\[
\boxed{(2, 1), (5, 4)}
\]