sub f{%h=@_;for(values %h){for(@$_){$h{$_}=[]if!$h{$_}}} sort{(grep /^$b$/,@{$h{$a}})?1:-1}keys%h}