while () { if (/$pattern/) # matches work by default on $_ { do something with $_; } }