use warnings; use strict; use Data::Dump::Streamer; my %lookup; my $main; my $action; my $text; while () { chomp; if (m/^Main\b/ .. m/^End\b/) { # Process Main/End blocks next if ! /Name = (\w+)/; $main = $1; } elsif (m/^Sub\b/ .. m/^End\b/) { # Process sub/end blocks $action = $1, next if /Action = Find: (\w+)/; $text = $1, next if /Text = (.*)/; next if ! /^End/ or ! defined $text; # Here if we have an End and $text is defined $lookup{$action} = $text if defined $action; my $key = $main; $key = $lookup{$key} if $key =~ /^\w\w$/; push @{$lookup{$key}}, $text; $action = undef; $text = undef; } } Dump (\%lookup);