string matching optimization