use strict; use warnings; my $foo = '1Z1'; $ENV{Z1Z1} = '3,2,1'; for (1..5) { my $x = '?'; if ($ENV{'Z' . uc $foo}) { ($x, $ENV{'Z' . uc $foo}) = split /,/, $ENV{'Z' . uc $foo}, 2; } print $x, $/; }