#! perl -slw use strict; my @things_to_sort = ( { author => 'bart', title => 'skateboarding' }, { author => 'lisa', title => 'postmodernism' }, { author => 'marge', title => 'hairstyles' }, { author => 'lisa', title => 'THIS BOOK FIRST' }, { author => 'homer', title => 'donuts' }, { author => 'bart', title => 'coolness' } ); my $firstTitle = 'THIS BOOK FIRST'; ## Find the author of the title my $firstAuthor; $_->{ title } eq $firstTitle and $firstAuthor = $_->{ author } for @things_to_sort; die "Title $firstTitle not found" unless $firstAuthor; my @sorted = map{ $_->[0] } sort { $a->[ 1 ] cmp $b->[ 1 ] } map { [ $_, sprintf "%s%s%s\0%s\0", $_->{ title } eq $firstTitle ? chr(0) : '', $_->{ author } eq $firstAuthor ? chr(0) : '', lc( $_->{ author } ), lc( $_->{ title } ) ] } @things_to_sort; printf "%-8s %-20s %-6s %-10s\n", %$_ for @sorted; __END__ c:\Perl\test>junk title THIS BOOK FIRST author lisa title postmodernism author lisa title coolness author bart title skateboarding author bart title donuts author homer title hairstyles author marge