in reply to Processing text file

What have you tried? How hasn't it worked? Please see How do I post a question effectively?. In particular, given that you are trying to read input from a file, it is important that we can see how the file is formatted. This can be accomplished by wrapping the input file contents in <code> tags. The same should be done for your expected output.

The simplest file data structure that matches your spec as I understand it is a hash of arrays. See perllol for some background on these structures. The following code demonstrates some of the fundamentals required to process input in the way you've described:

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my $input = <DATA>; my @data = split /\s+/, $input; my $last_display; my %results; for my $datum (@data) { my ($key, $value) = split /=/, $datum, 2; if ($key eq 'displaynum') { $last_display = $value; } if ($key eq 'value') { push @{$results{$last_display}}, $value; } } print Dumper \%results; for my $key (keys %results) { print join "\t", $key, @{$results{$key}}, "\n"; } __DATA__ displaynum=00 value=Some0 displaynum=01 value=Some1 displaynum=02 valu +e=Some2 value=Some3 __END__ $VAR1 = { '01' => [ 'Some1' ], '00' => [ 'Some0' ], '02' => [ 'Some2', 'Some3' ] }; 01 Some1 00 Some0 02 Some2 Some3

If this does not provide a clear road map for how to proceed, please post some code and well-formatted input and expected output and we'll see what we can do.