#!/usr/bin/perl use warnings; use strict; while (my $line = ) { next if $line =~ /^\s*$/; #skip blank lines my ($label, @rest) = split ' ', $line; @rest = sort {$a <=> $b}@rest; #numeric sort foreach my $col (@rest) { print "$label $col\n"; } } =prints A 1 B 2 B 3 B 6 C 2 C 3 C 4 C 6 C 10 =cut __DATA__ A 1 B 3 6 2 C 3 4 6 2 10