in reply to reading file in Hash

$ perl -e' use Data::Dumper; my $data = <<DATA; 1 2 3 a p x b q y c r z DATA open my $FH, "<", \$data or die "Cannot open \$data $!"; my ( @headers, %hash ); while ( <$FH> ) { my @fields = split; if ( $. == 1 ) { @hash{ @headers = @fields } = (); } else { push @{ $hash{ $_ } }, shift @fields for @headers; } } print Dumper \%hash; ' $VAR1 = { '1' => [ 'a', 'b', 'c' ], '3' => [ 'x', 'y', 'z' ], '2' => [ 'p', 'q', 'r' ] };