My first suggestion would be to use an array, instead:
$foo = array();
while(<blah blah blah>)
{
$foo[$i] = 'some value';
$i++;
}
If you really need to use separate scalar variables, you could use "complex variable notation":
while(<blah blah blah>)
{
${'foo'.$i} = 'some value';
$i++;
}
But I do think the array approach is a lot more manageable.