$_ = "start this is the start this is another end first end start hello start inside of hello end there end"; ($re=$_)=~s/((\bstart\b)|(\bend\b)|.)/${[')','']}[!$3]\Q$1\E${['(','']}[!$2]/gs; @$ = (eval{/$re/},$@); print join"\n",@$ unless $$[-1]=~/unmatched/;