use Readonly; Readonly my %BGCOLOR => ( Extreme => 'red', ... ); Readonly my $DEFAULT_BGCOLOR => 'grey'; sub get_bg_color { my ( $severity ) = @_; return $DEFAULT_BGCOLOR unless exists $BGCOLOR{$severity}; return$BGCOLOR{$severity}; } my $bg = get_bg_color( $condition );