perl -nE '$f.=$_}{$t{$_}=()=$f=~/\Q$_/g for $f=~/^sub\s+(\w+)/gm;say "$t{$_} $_" for sort {$t{$b} <=> $t{$a}} keys %t;' $FILE