while (){ if (/$tool_number/) $continue = 1; } if (/$end_tool/) $continue = 0; } if ($continue){ print $_; } }