while( $line = ) { next unless $line =~ m<\s+(\S+)\sHOLDS\s(.+)>x; $key = $1; #Obtains first_distribution, etc if ($line =~ /(\S+_Lower)\sHOLDS\s\S+/i) { $base_type = $1; #obtains parent config ID (eg SWG_Lower ) while ($line =~ m<\s(\S+):\s(completion).+>gx) # obtaining attributes { push(@{$base{$base_type}}, $1);}} # push each attribute associated with parent ID into an hash of arrays # eg A dump from the hash looks like this which is correct SWG_Lower:: total_dist total_finish total_cancel LOADED_Lower:: total_finish, total_cancel : CONFIG_Lower: total_cancel next unless exists $results{$key}; # I do this incase there are distribution ids in the file which are not in my hash