Please help me with my output for my program

Hello All,
iam a new memeber today i joined this forum.
hope i will get help. the below program takes input strings and give reverse of input string.

[ -a display ] && mv /home/test1/programs/display /home/test1/programs/old
echo " Please enter the test "
read a
echo "$a" > file
wc -c  file > file1
perl -pi -e "s|[a-z]||g" file1
b=$((`cat file1`-1))
#b=$(($b-1))
echo "$b"
for (( i = "$b" ; i >= 1 ; i-- ))
do
cat file | while read line
do
x=`echo $line | cut -c"$i"`
echo -e "$x \c" >> display
done
done
#cat display
perl -pi -e "s| ||g" display
cat display

Iam using the perl command at the eof line to replace single space with nothing.

but iam getting
Please enter the test

i/p: god is great

o/p: taergsidog

but if i dont use perl command at the eof line then my output is .

o/p:

t a e r g   s i   d o g

you can see in the second o/p there is a single between each character i want to remove that and want no space between each character and want only one space between the words instead of two spaces.

Thanks,
Amey

 
echo -e "$x\c"