Multiphase flow in petroleum transfer lines with different flow patterns considering the variation of pressure and temperature has been studied. The corrosion in carbon steel pipes is modeled and the optimum injection rate of inhibitor to control the corrosion rate is studied for different pipeline conditions. The flow pattern is recognized using the models presented in the references for different conditions of gas flow considering thermal and hydraulic situations. The optimization is carried out by genetics algorithms. The effect of gas CO2 and H2S mol fraction on the inhibitor injection rate is studied.