Loop through subdirectories to gzip files

I have a directory has many subdirectories. Each subdirectories has several very large files. Some of the large files already compressed (*.Z). I need to uncompress those files if they are *.Z files then gzip them to save more space. But those files are too large so they can only be done uncompress and gizp one file at a time. Please be aware not every file are compressed. File name could be: abc.xyz.Z or abcd.xyzw I need to make them as abc.xyz.gz and abcd.xyzw.gz

Any good tip?
Thanks

Hope you for something like this

find /dir -type f|while read fname
do
   extn=`echo $fname|awk -F'.' '{print $NF}'`
   if [ extn = "Z" ]
   then
     unzip $fname
     fname=`echo $fname|sed 's/\(.*\)\(.Z\)/\1/'`
   fi
   gzip $fname
done

Regards,

Ranjith

thanks a lot Ranjith.