for my $type (keys %$curr_struct_pos) { for my $index (1..@{$cur_struct_pos{$type}}-1) { $path="Global".$type. "Def:".$curr_struct_pos{$type}[$a]. ".def"; #much easier to read $curr_struct_pos{$type}[$a] = extract(); }