foreach my $x_pos (@{$params{x_pos}}) { foreach my $y_pos (@{$params{y_pos}}) { . . . my $result = function($x_pos,$y_pos,...) . . . } }