open my $FH, "<", "file.txt" or die "Cannot open file.txt $!"; while (<$FH>) { # ... } #### use strict; use warnings; use Data::Dumper; my $sheet; my $count = -1; while( ) { chomp; $count++; # skip header next unless $count; my $row; @$row = split( /,/, $_ ); push @$sheet, $row; } #my @sorted = sort {$a->[0] <=> $b->[0]} @$sheet; my @sorted = sort {$a->[1] cmp $b->[1]} @$sheet; print Dumper \@sorted; __DATA__ HEADER 1,Beginning C,Beginning C1 2,Beginning C++,Beginning C++1 12,navy blue,navy blue1 3,Python Intro,Python Intro1 8,Baker's dozon,Baker's dozon1 9,Jumbo frames,Jumbo frames1 4,Acme cook book,Acme cook book1 5,Jumping Jack Flash,Jumping Jack Flash1 6,Zebra,Zebra1 7,Ace hardware,Ace hardware1 10,Attack show,Attack show1 11,car 54 where are you,car 54 where are you1 13,navy gold,navy gold1 #### use strict; use warnings; use Data::Dumper; my @sheet; while( ) { chomp; # skip header next if $. == 1; my @row = split( /,/, $_ ); push @sheet, [@row]; } my @sorted = sort {$a->[0] <=> $b->[0]} @sheet; #my @sorted = sort {$a->[1] cmp $b->[1]} @sheet; print Dumper \@sorted; __DATA__ HEADER 1,Beginning C,Beginning C1 2,Beginning C++,Beginning C++1 12,navy blue,navy blue1 3,Python Intro,Python Intro1 8,Baker's dozon,Baker's dozon1 9,Jumbo frames,Jumbo frames1 4,Acme cook book,Acme cook book1 5,Jumping Jack Flash,Jumping Jack Flash1 6,Zebra,Zebra1 7,Ace hardware,Ace hardware1 10,Attack show,Attack show1 11,car 54 where are you,car 54 where are you1 13,navy gold,navy gold1