my @widgets = ('Widget', 'Water', 'Bridget', 'Widgets');
my $string = 'This page is about X-Wa';
my ($search) = $string =~ /X-(\w+)$/;
my ($result) = grep{ $_ =~ /^${search}/ } @widgets;
$string =~ s/${search}$/${result}/;
have you tried this yet?
(Widget|Widge|Widg|Wid|Wi|W)
Now that I think about it, if the string is truncated, how would you know if a 's' character was supposed to be attached to the widget name or for that matter what if there is an 's' character in the middle of the widget name.
I had tried that, although I had left out the entire word Widget because I thought it was silly to be replacing the correct word with the same word, and it was doing the same thing as I posted above, it was returning Widgett (double tt) somehow. So I added Widget to the OR as in your suggestion and that seems to have fixed the double tt thing and it's looking promising now. Thank you.
just to explain: Widget was in there to match the complete word, not so much to replace it with itself. When you took it out, "Widget" was matched by "Widge" and "Widge" was replaced by "Widget", thus resulting in Widgett".
Widget is matched by Widge, but Widget still exists in its entire form - then Widge gets replaced by Widget, leaving the underlying t from the original Widget, hence Widgett? It would show better what I'm saying if I could use colors, but the board doesn't seem to allow them. I hope that all makes sense and thanks for helping me to understand! I think I got it.
I have a somewhat related question also but I'll start a new topic for that.