If I read the code right, it calls regexec for every single character on every single line. No wonder that takes a while! Just call it once and it'll search for its match quite nicely. If that's not enough, the two obvious optimizations are... 1. If the pattern contains no regexp characters (and that is very common), do a strstr. 2. If the pattern must start with a specific character, search for that by itself. M. - : send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html