perl -i.bak -0ple 's!\s*(.*?)(.*?)!$2$1$2!is' file.html