It could be due to irritable bowel syndrome. Fiber supplements along with probiotics, antispasmodics and antidepressants would provide relief.
If you're more worried about your situation then it is better to consult with the doctor.
Best of luck!
Not enough history provided. This can be anything from idiopathic to low-fiber diet to anorectal stricture to irritable bowel syndrome; cannot exclude infection, inflammation, or cancer. If symptoms persist, see a gastroenterologist.