You are likely to have had an anal fissure. Anal fissure is a linear tear in the anal mucose.
Anal fissures occur in adults due to passage of hard stools. They can also occur due to straining during constipation, diarrhea, anal intercourse, etc. They are benign conditions and will usually heal spontaneously. However, they amy rarely be a sign of an underlying disease. Some conditions like Crohn's disease or Syphilis can also cause this.
Hence if you are having recurrent anal fissures you need to show this to yur doctor.
Most anal fissures heal spontaneously. You can try home treatment initially.
High fiber diet – take a high fiber diet which will keep the stool soft.
Stool softeners – you can take OTC stool softeners like Docusate
OTC ointments – you can use OTC ointments like Cortaid.
Discuss this with your pharmacist.
Usually the fissure will heal with this.
If it persists beyond 5 days you need to show your doctor.
Your doctor can prescribe other medicines like Nitroglycerine or Nifedipine ointments, oral Nitroglycerin or Nifedipine and Botox infections.
Rarely surgery is required for chronic fissures.
Try out these home treatments first but if it persists show your doctor.