the invention relates to applying corrosion inhibitor within a foam matrix to the top of the line of wet gas pipelines . the environment within a hydrocarbon containing pipeline may include fluids that form strong acids in the gas space at the upper portion of the pipeline and can rapidly corrode a carbon steel pipeline . the inventive solution is to provide a foam matrix created by a combination of foaming agent , foaming gas and corrosion inhibitor that are each selected to be compatible with each other and with the hydrocarbon mixture to form a stable foam matrix that treats the top of the line position for the length of the pipeline . a foam breaking agent at the end of the pipeline can be injected , if needed .