use strict; use warnings; open my $IN, '<', 'list.txt' or die "Cannot open 'list.txt' because: $!"; my ( undef, @ss ) = split ' ', <$IN>; my %s; while ( <$IN> ) { my ( $aa, @prs ) = split; @{ $s{ $aa } }{ @ss } = @prs; } close $IN;