foreach $_ (sort { (split /\t/, $a)[4] cmp (split /\t/, $b)[4] } @database_in) { ..... }