$underscore = "_"; for($i = -180; $i < 181; $i = $i+5) { $j = $i+5; if(($x >= -180) && ($x < -175) && ($y >= $i) && ($y < $i+5 )) { $k++; $x1 = "substr($i, 1, 3)"; $x2 = "substr($i, 1, 3)"; $y1 = substr($i, 1, 3); $y2= substr($j, 1, 3); # attempting to name array according to value range $array = "array$underscore$x1$underscore$x2$underscore$y1$underscore$y2"; $count = $count +1; $array[$k] = ($count); print "$array[$k]";