<>; @S=map s/$/{/r,<>; while(@S){ @S=sort@S; $S[0]=~s/\w//?print$&:shift@S }