while () { ...do something.... ... print if /$pattern/; # simple first attempt }