... $rlButtonOrder = fitToColsVSort($numHosts, $numCols); foreach (0 .. $#nodeList) { my $buttonName = $nodeList[$_] . "Button"; $$buttonName = $hostSelectFrame->Button( ... -text => $nodeList[$_], ... -width => $longestName)->grid( -row => $rlButtonOrder->[$_]->[0], -column => $rlButtonOrder->[$_]->[1], ... ); $$buttonName->configure( -command => [\&gotoHost, $nodeList[$_]]); } ...