Here's an example of using format as well as performing both sets of replacements in a single pass by matching a regular expression:
(while (re-search-forward "\\(KR-?\\)MET" nil t)
(replace-match (format "%s%d" (match-string 1) r)
Or adapting your concat approach:
(concat (match-string ...
OK, here's what I am working with right now:
(defun org-execute-file-search-in-fortran (s)
"Find the link search string S as a key. May be a regex."
(when (eq major-mode 'f90-mode)
;; Yes, we want to do the search in this file.
(if (string-match "^/\\(.*\\)/$" s)
;; A regular ...
If I were doing this as a one-time task, not expected to be done again, I would use keyboard macros with ordinary search (no regexps). It seems easiest to do it in two steps. First make sure there is one empty line before and after headers, and then change it to two before the main headers.
f3 Define a macro
C-s C-j # C-a ...