in reply to Why is my program so slow even though I've used hashes?

Bug: The following do anything (useful):

$res =~/\S/g; $domchain =~/\S/g; $pdbchain =~/\S/g;

You want:

$res =~ s/\s//g; $domchain =~ s/\s//g; $pdbchain =~ s/\s//g;

Also, all over you have "$var" which needlessly makes a copy of $var. Drop the quotes. You want just $var. For example,

if("$domchain" eq "$pdbchain")
should be
if($domchain eq $pdbchain)