my %hash = map { my @things = split(/~|\n/, $_); my $value = pop @things; map { $_, $value } @things; } @data;