Thanks for your question. Many people wonder about their foreskin and erections. First, it is a good sign that you can pull back your foreskin without any pain when your penis is not erect.
Usually the foreskin will retract (or slide back) on its own during an erection. If the foreskin does not retract on its own, it is a good idea to see a healthcare provider. Sometimes this can be a sign that the frenulum, the skin that connects the glans (head of the penis) to the foreskin, is short. A healthcare provider will examine the penis. They can let you know if everything looks normal, if you need any prescribed creams, or if you need to see an urologist (a doctor who specializes in caring for male genitals and urinary system). We definitely recommend seeing your healthcare provider sooner if you notice any pain with an erection.