foreach my $key (keys %other_hash) { foreach (@{$other_hash{$key}} { for (my $i=0; $i<=$#{$points_by_name{$key}} $i+=2) { my @temp = @{$other_hash{$key}}[$i..$i+3] foreach (@temp) { sub($x0, $y0, $x1, $y1, @temp) } } } }