($x, $ENV{Z1Z1}) = ( '3', '2,1' ); # first time ($x, $ENV{Z1Z1}) = ( '2', '1' ); # second time ($x, $ENV{Z1Z1}) = ( '1', undef ); # third time #### my @arr = split /,/, $ENV{'Z' . uc $foo}, 2; $x = shift @arr; $ENV{'Z' . uc $foo} = scalar @arr ? $arr[0] : ''; # set to empty string if nothing available