in reply to Using hash keys to separate data

If you split the lines into 2 parts, instead of in as many as the line contains, then you'll keep the entire row. Also, you can assign to a list of scalars, whih is easier to handle than an array.

And for the rest, as wfsp already said: push the data onto the anonymous array which comprise the values of the hash (autovivified, so don't worry about the anonymous array not existing).

while (<REG>) { chomp; my($key, $data) = split "\t", $_, 2; push @{$R{$key}}, $data; }
After that it's just a matter of looping through the keys, and print out the contents of the array.
foreach my $key (keys %R) { open my $fh, '>', "$key.out" or die "Cannot open file $key.out: $! +"; foreach my $row (@{$R{$key}}) { print $fh "$key\t$row\n"; } }