Yoz's New Improved Collapsible Travelling Capitalisation-And-Punctuation-In-Place-Alphabetiser (CAPIPA)

 

print grep(s/\w+([\.']\w+)*/recap($&)/ge||$_,
grep(s/\w+([\.']\w+)*/(push(@w,$&),$&)[1]/ge||$_,
<>),do {@w=sort {lc($a) cmp lc($b)} @w;''});
sub recap {local $_=shift;$w=shift(@w);
/^[A-Z][a-z]+/ and return ucfirst(lc($w));
/^[a-z]/ and return lc($w);
!/[a-z]/ and return uc($w);
return $w}

That's all there is to it!

Why not take CAPIPA for a spin? Enter the text to be alphabetised -- the more the better:

 

 

Starship Titanic Home

 

©1997 The Digital Village Ltd/Simon & Schuster Interactive Inc. All Rights Reserved.