for my $x ('x') { $x =~ s/x/X/ } #### 'x' =~ s/x/X/; #### chomp; my @line_array = split /[()\t+\s+]/; #### @full = map {$_ ? $_ : ()} @line_array; #### @full = grep { $_ } @line_array; #### @full = grep { defined $_ and length $_ } @line_array; #### @{$data[$readcounter]} = @full; #### push @data, \@full; #### use strict; use Data::Dumper; my @data; while () { chomp; my @line = grep { defined $_ and length $_ } split /[()\t+\s+]/; push @data, \@line; } @data = sort { $a->[0] <=> $b->[0] } @data; print Dumper \@data; __DATA__ 00000(IDR) 86480 22 41.435 40.696 40.728167 0 FRM 3 00015( B ) 9312 24 45.460 43.808 42.001 409 208 FRM 0 00002( P ) 35248 24 38.568 39.327 40.641 253 53 FRM 2 #### use strict; use Data::Dumper; use Sort::Key qw(nkeysort_inplace); my @data; while () { chomp; my @line = grep { defined $_ and length $_ } split /[()\t+\s+]/; push @data, \@line; } nkeysort_inplace { $_->[0] } @data; print Dumper \@data; __DATA__ 00000(IDR) 86480 22 41.435 40.696 40.728167 0 FRM 3 00015( B ) 9312 24 45.460 43.808 42.001 409 208 FRM 0 00002( P ) 35248 24 38.568 39.327 40.641 253 53 FRM 2