$/ = "\n"; while ( ) { chomp; print "$_\n" for sort { $a <=> $b } split /\n/; print $/ if ! eof DATA; }