Hey! I had no idea s/// returned anything. Also a more straightforward way to write the regex. Problem is, with the or, the second sub doesn't get executed if the first one matches, so there is still the trailing quote on examples 1 and 4. I suppose one could do
my @items = ('"Title Text Example"', 'Title Text Example', ' Title Tex
+t Example ',' "Title Text Example"');
foreach my $title (@items) {
my $changed = 0;
if ($title =~ s/^[\s"]+//) { $changed=1; }
if ($title =~ s/[\s"]+$//) { $changed=1; }
if ($changed) {
print "$title\n";
}
}
But that doesn't seem very elegant.