# give ourselves a short name # in a short scope my $o = $outdate{$key1}; if ($lec and $lec = $o) { # set the default my $cell = $lecsquare; if ($tacho eq $o) { $cell = $tacholecsquare; } else { for my $i (0..3){ $cell = $pmilecsquare if $pmis[$i] eq $o; } } $worksheet1->write($r, $y, "L", $cell); }