using for and if in text matching