for (sort { $module{$a} <=> $module{$b} } keys %module) { printf "%04d, %s\n", $module{$_}, $_; } #### /^use\s+([^\s;]+)/ && $_{$1}++ while <>; printf "%04d, $_\n", $_{$_} for sort { $_{$b} <=> $_{$a} } keys %_;