I've seen the same thing with tail -f, and it confuses me as well. I look forward to an expert answer! In this case, sed alone can handle the job, if you want to avoid perl: tail -f mylog | sed -n '/smtg/s/end/notend/p'