in reply to Trying to use substring to find a reverse complement in DNA,
Your book ran the loop backwards to reverse the string. You can run it forward, but you must reverse the concatenation:
$complement = $base . $complement; [download]