sub new { my ($class, @ids) = @_; my @users; my $sql = "SELECT user_id, user_name FROM users WHERE user_id IN (" . join(",", @ids) . ")"; my $sth = $dbh->prepare($sql); $sth->execute(); $sth->bind_cols(\my ($id, $name)); while ( $sth->fetch() ) { push @users, bless({ user_id => $id, user_name => $name, }, $class); }; return wantarray ? @users : $users[0]; }