use Switch; for my ($x=0;$x<4;$x++){ switch ($x) case 0 for my $i (@$times) { print qq{}; } case 1 for my $i (@$times){ print qq{"$i"}; } etc., etc.