Of course, if a name is longer than 45 char's this will silently eat the start of that name. Im not sure if its at all possible to handle this nicely with a regexp, at least I have never managed to do it. Problems is how to handle the case where you cant break the input the way you want.
Now, it wasn't really specified how to handle this situation, maybe break on whitespace instead? Or just simply overflow? (One application I work with frequently will hang forever trying to break a line longer than 80 characters if there are no spaces in it:-). Anyway, if overflowing is the solution for this particular problem, then Text::Wrap might come to the rescue:
use Text::Wrap qw(wrap);
my @parts=do {
local $Text::Wrap::columns=45;
local $Text::Wrap::huge='overflow';
local $Text::Wrap::separator=",\n";
local $Text::Wrap::break=qr/\s*,\s*/;
split /\n/, wrap('','',$string);
};
gc |