for my $key ( sort { $a eq 'Foo' and return -1; $b eq 'Foo' and return 1; return 0; } keys %hash ) { # do stuff }