I\'m reading all elements from list (of strings) and replacing a substring if it matches a pattern. The problem is after reading the last element from list, I\'m getting an erro