in reply to I just can't see the error in this code

You forgot:
use strict; use warnings;
As an aside, you also might be over-commenting, e.g.
my %final; # Hash %final