my @switch_foo = ("a","b","c",...); for ($var) { my $junk = shift; while ($junk > 0) { print $switch_foo[$junk]); $junk--; } }