The algorithm to sort this problem is simple, just like you said in your question description, sort characters in each word first, then sort these sorted-word again.
Like this:
$ echo heya64 this is21 a good89 day91 | perl -anE 'say(join " ", sort(map { join "", sort split // } @F))'
12is 19ady 46aehy 89dgoo a hist
solved Sort words and then the sentence including digits and characters in Shell scripting or perl scripting [closed]