#!/usr/bin/perl use warnings; use strict; use Data::Dumper; use Data::Dump qw(pp); my @results = (["chpt10_2", "sent. 2", "alice", "nsubj", "animals", "protect"], ["chpt12_1", "sent. 54", "bob", "nsubj", "cells", "protect"], ["chpt25_4", "sent. 47", "carol", "nsubj", "plants", "protect"], ["chpt34_1", "sent. 1", "dave", "nsubj", "cells", "protect"], ["chpt35_1", "sent. 2", "eli", "nsubj", "cells", "protect"], ["chpt38_1", "sent. 1", "fred", "nsubj", "animals", "protect"], ["chpt54_1", "sent. 1", "greg", "nsubj", "uticle", "protect"] ); my %freq; foreach ( map{$_->[4]}@results) #feeds in list of animals, cells, uticle, etc. { $freq{lc $_}++; } @results = sort {$freq{lc $b->[4]} <=> $freq{lc $a->[4]} #freq order or $a->[0] cmp $b->[0] #text col 0 } @results; print pp(\@results); __END__ [ ["chpt12_1", "sent. 54", "bob", "nsubj", "cells", "protect"], ["chpt34_1", "sent. 1", "dave", "nsubj", "cells", "protect"], ["chpt35_1", "sent. 2", "eli", "nsubj", "cells", "protect"], ["chpt10_2", "sent. 2", "alice", "nsubj", "animals", "protect"], ["chpt38_1", "sent. 1", "fred", "nsubj", "animals", "protect"], ["chpt25_4", "sent. 47", "carol", "nsubj", "plants", "protect"], ["chpt54_1", "sent. 1", "greg", "nsubj", "uticle", "protect"], ]