in reply to Swap the characters

C:\>perl -le"$_=shift; s/\b(\w)(\w*)(\w)\b/$3$2$1/g;print" "12345 Abc +D" 52341 DbcA C:\>perl -le"$_=shift; s/\b(\w)(\w*)(\w)\b/$3$2$1/g;print" "12345 52341 C:\>perl -le"$_=shift; s/\b(\w)(\w*)(\w)\b/$3$2$1/g;print" "AbcD DbcA C:\>perl -le"$_=shift; s/\b(\w)(\w*)(\w)\b/$3$2$1/g;print" "AbcD 1234 +5" DbcA 52341 C:\>

Replies are listed 'Best First'.
Re^2: Swap the characters
by AnomalousMonk (Archbishop) on Apr 14, 2009 at 08:10 UTC
    This will only operate on  \w characters, and I took the requirement of the OPer's homework problem to be to operate on any character. Also, it operates on substrings, and I understood the requirement to be to operate on the entire string.
    >perl -le "$_=shift; s/\b(\w)(\w*)(\w)\b/$3$2$1/g; print" *%$# *%$#