#!perl undef $/; $text = ; while ($text =~/foo(.*?)bar/g) { manipulate ($1) } sub manipulate { print "@_\n"; } __DATA__ foo this is one example bar this is a line I don't care about foo here's another keeper! bar foo yet another bar and a line to reject