in reply to how to declare the hash
my %flag;
Update: for more see Hashes in Perl and perldata.
Well done is better than well said. -- Benjamin Franklin