while($currentLine =~ /\s$pattern\s/g){ $count +=1; }