$ perl -MData::Dumper -F, -lane '@F % 2 and push @D, {q{Stamp},@F} or $D[-1] = { %{$D[-1]}, @F } }{ print Dumper @D' input.txt