$hash{$_} = [] for ('A'..'Z'); # prepare some empty arrayrefs $file_name =~ /^(.)/; # Mmm... It would be better to use a substr here :/ push @{$hash{uc($1)}}, $infoline; # push an $infoline, first by uppercasing the key