Make a number palindrome
Perl, 32 chars

s/((.)(?1)\2|.?)$/$&amp;.reverse$`/e


Needs Perl 5.10 or later for regex features, but no special command-line switch.

Sample use:

$ perl -pe 's/((.)(?1)\2|.?)$/$&amp;.reverse$`/e' &lt;&lt; EOT
&gt; 12
&gt; 232
&gt; 2323
&gt; 1012121
&gt; EOT
121
232
23232
101212101


Uses Perl 5.10's recursive regex extensions to match the longest trailing palindrome as such:

m/
    (      # paren 1 - a palindrome is either:
      (.)  # paren 2 - a character
      (?1) # a palindrome as defined in paren 1
      \2   # the same character as in paren 2
    |        # or:
      .?   # a 0- or 1-character string
    )
    $      # at end of string
/x


It then replaces it with itself ($&amp;) and appends whatever the string started with ($`), reversed.