# define a hash of sub refs, keyed by sub name my %dbsub = ( foo => \&foo, bar => \&bar, baz => \&baz, ); # now run your query, and then: while ( my @db = $result->fetchrow ) { $LHC_OPTIONS .= ( exists( $dbsub{$db[2]} )) ? $dbsub{$db[2]}->() : join(':', @db[0,1]).'
'; } #### while ( my @db = $result->fetchrow ) { if ( exists( $dbsub{$db[2]} )) { $LHC_OPTIONS .= $dbsub{$db[2]}->(); } else { warn "Unknown sub name in DB: $db[2]\n" if ( $db[2] ); $LHC_OPTIONS .= join(':', @db[0,1]).'
'; } }