my %statistics = ( 1 => [ "foo", "bar" ], 2 => [ "baz", "bletch" ], 3 => [ "quux" ], ); #### # if we havent hit this line yet, add an array # reference to %statistics at this line number. if (not defined $statistics{$line_number} ) { $statistics{$line_number} = [ $thisline ]; } # if we have hit this line, then we have an # array reference already and all we have to do # is push it. if (defined $statistics{$line_number} ) { push @{ $statistics{$line_number} }, $thisline; }