>perl -wMstrict -le "my @cols = qw(bar wobble mosh hop); my %hash = ( wibble => $cols[1], foo => $cols[0], hip => $cols[3], mish => $cols[2], ); my %i_map = map { $cols[$_] => $_ } 0 .. $#cols; print join ' ', qq{keys sorted by \@cols index of value: \n}, sort { $i_map{ $hash{$a} } <=> $i_map{ $hash{$b} } } keys %hash ; print join ' ', qq{values sorted by \@cols index of value: \n}, sort { $i_map{$a} <=> $i_map{$b} } values %hash ; " keys sorted by @cols index of value: foo wibble mish hip values sorted by @cols index of value: bar wobble mosh hop