foreach(@lines) { while(m{$pattern}g) { $count++; } }