#!/usr/bin/perl -w use strict; my $data = get_data_from_somewhere; # First split the data up into a 2D structure my @struct; for (split /\n/, $data) { push @struct, [ split /:/ ] } # Now we sort the struct on the second element of the nested arrays @struct = sort { $a->[1] cmp $b->[1] } @struct;