# Remove the third line in the file perl -i.bak -ne 'print unless $. == 3' file # Remove any lines that contain foo perl -i.bak -ne 'print unless /foo/' file # Remove foo from all lines perl -i.bak -pe 's/foo//g' file # Substitute foo with bar on all lines perl -i.bak -pe 's/foo/bar/g' file