in reply to How can I improve my inefficient codes?

foreach my $name(keys %input) { if ($input{$name}[1] eq $chr) {

That's a source of needless inefficiency. If you use $chr as the hash key (and not $name as you do now), you can substitute the loop by a simple hash lookup. If there can be multiple lines with the same $chr, you need to use a hash-of-arrays-of-arrays, and iterate over the outer array.