in reply to Strange array reference behaviour (bug?)

The easiest way to work around this feature is to just use a variable other than $test inside your loop:
foreach my $test (@$ref) { my $test2 = substr($test, 0, 2); }