while () { if (/\b$first\b/ .. /\b$last\b/) { $in = 1; print; } elsif ($in && /\b$last\b/) { print; } else { $in = 0; } }