my $test = eval "sub { print 'hello world' }"; $test->(); # prints the ever-classic "hello world" #### my %hash = ( 'Lisa' => [ 'F', 6, 150, 'Blonde', 'Blue' ], 'Homer' => [ 'M', 40, 105, 'Bald', 'Blue' ], 'Bart' => [ 'M', 9, 120, 'Blonde', 'Brown' ], 'Marge' => [ 'F', 36, 135, 'Blue', 'Blue' ], 'Maggie' => [ 'F', 1, 130, 'Blonde', 'Blue' ] ); sub createSortRoutine { my (@ordered_values) = @_; return sub { my ($left, $right) = @_; my $result; foreach (@ordered_values) { $result = ( ($hash{$left}->[$_] =~ /^\d+$/) ? $hash{$left}->[$_] <=> $hash{$right}->[$_] : $hash{$left}->[$_] cmp $hash{$right}->[$_] ) unless $result; } return $result; }; } my $sorter = createSortRoutine(0, 2, 3); print join "\n" => sort { $sorter->($a, $b) } keys %hash; # NOTE: this code not thoroughly tested, i lifted it from # and old module of mine and hacked it for this example. __DATA__ Maggie Marge Lisa Homer Bart