És ez hogy hangzik (nem tudom kipróbálni, lehet hogy nem is fut)?
my $regex = qr/(?:([^']++)|('))/xs;
my $result = "";
pos($file_content) = undef;
my $in_quote = 0;
while ($file_content =~ m/$regex/g)
{
my $fragment;
if (defined $1)
{
$fragment = $1;
$fragment =~ s/\h+/ /g unless ($in_quote);
}
else
{
$fragment = $2;
$in_quote = 1 - $in_quote;
}
$result .= $fragment;
}