\documentclass{article}
\usepackage{perltex}
\perlnewcommand{\tarai}[3]{
  if($_[0] <= $_[1]){
    return $_[1];
  } else {
    return latex_tarai(
      latex_tarai($_[0]-1, $_[1], $_[2]),
      latex_tarai($_[1]-1, $_[2], $_[0]),
      latex_tarai($_[2]-1, $_[0], $_[1]));
  }
}
\begin{document}
  $\mathrm{Tarai}(14,10,6) = \tarai{14}{10}{6}$
\end{document}