Plugboards can be arbitrary template programs, which can do what you suggest and much more. See http://calibre-ebook.com/user_manual/template_lang.html
, and in particular note the three program modes available (single-function, template program, and general program).
For very complicated templates, it might be easier to create a composite column and put the program there. It is rather hard to put something very complicated into the one line available in the plugboard dialog.