How to reverse a string using perl

Hello, I would like to reverse "All the best" to "best the All". I know if I split it on space on put in a array then I can print the reverse array. But here I would like to get it done without using array. is there a way?

I am doing kind of this but not sure what is missing to get the output as "best the All"

perl -le '$string = "All the best"; print scalar reverse $string'
tseb eht llA

Open in new window

beer9Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
ozoConnect With a Mentor Commented:
perl -le '$_="All the best";print join" ",reverse split'
0
 
ozoCommented:
or
perl -le '($string = "All the best") =~ s/(\S+)/reverse $1/eg;print scalar reverse $string'
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.