sub month_events { $sth = $dbh->prepare("SELECT * FROM hno_calendar WHERE year = $year AND month = $month"); $sth->execute(); while (my $ref = $sth->fetchrow_hashref()) { if ( !exists $events{ $ref->{day} } ) { $events{ $ref->{day} } = $ref->{title}; } else { $events{ $ref->{$day} } .=$ref->{title}; } } }