If you have control over the format the string is generated in, then why not use a well-established format like CSV? The defaults of Text::CSV are that fields are separated by commas, if a field contains commas (or whitespace), it is surrounded by double quotes, and if a double quote needs to be escaped, then it is doubled up. For example:
use warnings;
use strict;
use Text::CSV;
my $data = <<'END';
1,"Text,with,commas and ""quotes""",X,99
END
open my $fh, '<', \$data or die $!;
my $csv = Text::CSV->new({ binary=>1, auto_diag=>2 });
while ( my $row = $csv->getline($fh) ) {
print "<<$_>>\n" for @$row;
}
$csv->eof or $csv->error_diag;
close $fh;
__END__
<<1>>
<<Text,with,commas and "quotes">>
<<X>>
<<99>>
Maybe I will take the plunge and post my 'lcd daemon with battery meter script' once it is completed.
Yes, that'd be interesting!