#!/perl -w use Data::Dumper; use strict; my %hash; my $current_comp = ""; my $current_mode = ""; my %the_hash; while () { chomp; my ($coord,$data) = split /=>/; my ($row,$col) = split /,/, $coord; if ($col == 0) { $current_comp = $data; next; } if ($col == 2) { $current_mode = $data; next; } if ($col == 4) { push @{$the_hash{$current_mode}{$current_comp}{'commands'}}, $data; next; } } print Dumper(\%the_hash);