while (){ if (/$tool_number/) $continue = 1; } if (/$end_tool/) $continue = 0; } if ($continue){ print $_; } } #### while (<^(*?)$tool_number(.*)$/) {