use strict; use warnings; my @data; # this will be an array of arrays while() # read from __DATA__ for simplicity { chomp; if($_ eq '') { push @data, [] } else { push @{$data[-1]}, $_ } } foreach (@data) { print "\n", join("\n", sort { $a <=> $b } @$_), "\n"; } __DATA__ 22 1 3 4 2 44 #### 1 3 22 2 4 44 Tool completed successfully