Perl s///
can do what you want, but I don't think what you're asking for is what you need.
$ echo SGVsbG8gQmFzZTY0Cg== | perl -MMIME::Base64 -pe 's/(.+)/decode_base64($1)/e'
Hello Base64
What's actually happening:
echo SGVsbG8gQmFzZTY0Cg== | sed -r "s/(.+)$/$(decodeBaseSixtyFour \\1)/"
- Before sed starts reading input, the shell notices the process substitution in the double quoted string
- the
decodeBaseSixtyFour
function is called with the string"\\1"
- base64 chokes on the input
\1
and emits the error message - the function returns the string
"\1 is decoded to "
- now the sed script is
's/(.+)$/\1 is decoded to /'
which is how you get the last line.