in reply to Trying to use substring to find a reverse complement in DNA,

UPDATE: Please disregard this suggestion. I did not notice the explicit reverse.

Your book ran the loop backwards to reverse the string. You can run it forward, but you must reverse the concatenation:

$complement = $base . $complement;
Bill