in reply to Replacing duplicate string

And this solution works always (it does no longer depend on Class voip coming right after the first priority):
use strict; use warnings; while (<DATA>) { if (((/^priority/ .. /^\s*$/) || 0) > 1) { s/priority/bandwidth/; } print; } __DATA__ Class control priority 5 Class voip priority 30 Class video priority 40 Class control priority 10 Class voip priority 25 Class video priority 45
It takes advantage of the fact that the return value of the .. operator in scalar context is 1 the first time the start condition is met.

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James