my $l = 0; map { defined $_ and print "$_\n" } map { ($_->[1] ne $l)? $l=$_->[1] : undef } sort { $a->[1] <=> $b->[1] } map { [s/[\D\n]//g, $_] } <>;