#! perl -sw use strict; #! The rounding may need some correction. sub Xtoix{ int($_[0]/(1066+2/3)+.5) } #! the closest approximate mapping functions sub Ytoiy{ int($_[0]/( 933+1/3)+.5) } #! I could derive from your limited sample data. my @grid; open GRIDS, 'yourgridsfile' or die $!; while() { #! Isolate the data my ($map, $grid, $subgrid, $x0, $y0, $x1, $y1 ) = split ','; my $ix = Xtoix( $x0 ); #! map to 0 based indexes my $iy = Ytoiy( $y0 ); #! build and store a hash with the data into the grid. $grid[$ix][$iy] = {map=>$map, grid=>$grid, subgrid=>$subgrid, x0=>$x0, y0=>$y0, x1=>$x1, y1=>$y1 }; } close GRIDS; open PLACES, 'yourplacefilename' or die $!; while() { my ($thingy, $x, $y)= split ','; # Forgot to split!! my $ix = Xtoix( $x ); my $iy = Ytoiy( $y ); my $adjusted = 0; my $gridref = $grid[$ix][$iy]; ++$adjusted, $ix-- if $x < $gridref->{x0}; ++$adjusted, $ix++ if $x > $gridref->{x1}; ++$adjusted, $iy-- if $y < $gridref->{y0}; ++$adjusted, $iy++ if $y > $gridref->{y1}; $gridref = $grid[$ix][$iy] if $adjusted; print $thingy, ' is on map ', $gridref->{map}, ' at grid ', $gridref->{grid}, ' subgrid ', $gridref->{subgrid}, } close PLACES;