I'm surprised you're getting any output. You're first while loop iterates over the entire file, populating %starthash. By the time the second while is encountered, there's nothing more to read, so its body is not executed once. But that's where the print statement is.