{ # these are only visible to the function my @settings = ( [ (0,0), "red", "E = 0" ], [ (1e-99, 1e-90), "orange", "1e-99 < E < 1e-90" ], ... ); sub color_and_msg { my ($boo, $tab, $balloon) = @_; my ($color, $msg) = ("black", ""); for (@settings) { my ($low, $high, $c, $m) = @$_; if ($low <= $boo and $boo < $high) { ($color, $msg) = ($c, $m); last; } } my $frame = $tab->Label( -bg => $color, -relief => 'sunken', -width => 10, ); $balloon->attach($frame, -balloonmsg => $msg) if $msg; return $frame; # if you need it } } #### my $frame = color_and_msg($boo, $tab, $balloon);