You don't have to make sure of having an array ref. for a particular key, your code $route{$key} ||= [];, as doing the push @{$route{$key}}, $line; will push onto an auto-vivified array ref. if one doesn't exist or push onto the existing ref. otherwise.