Naive pattern matching algorithm