echo -e 'zero\none\ntwo\n\n three' | perl -0777 -pe 's{\s*(one\ntwo)\s*?( *)}{\n\n\n\n$1\n\n\n\n$2}' zero one two three