perl -i.orig -pe 'if ($c) { s/^line(\d+)/name$1/ } $c = /^\$\$\$\$$/; ' input.txt