sub sort_array { my ($col, $dir, @foo) = @_; if ($dir eq 'a') { @sortedarry = map { $_ ->[0] } sort { $a->[1] <=> $b->[1] || $a->[2] <=> $b->[2] || $a->[3] <=> $b->[3] } map { my @cols = split /,/; [ $_, $cols[1], $cols[2], $cols[3] ] } @foo; return @sortedarry; } else { @sortedarry = map { $_ ->[0] } sort { $b->[1] <=> $a->[1] || $b->[2] <=> $a->[2] || $b->[3] <=> $a->[3] } map { my @cols = split /,/; [ $_, $cols[1], $cols[2], $cols[3] ] } @foo; return @sortedarry; } }