Are you asking for help with shell or regex? Are you honestly editing this regex as presented in a shell script? You know how you got newlines and indenting in your shell script? Your regex is easily 10 times more complex than hilite_tail. You might need it in one line for your shell(doubtfull) but its silly for human to write code/regex without whitespace. Accoreing to your code Spanish verb endings is a static list of 20ish words -- if you think that requires optimization you havent timed it. To speedup what you have Replace guts of hilite_tail with single call to perl that does it.