in reply to Separating multiple keyword search input

The following code isn't intended to be a cut-n-paste solution, but rather a demonstration of a technique you can use to search for multiple keywords and do replacements based on those keywords.

my %replacements = qw/men women houses homes cats dogs venus mars carpet rug full empty/; my $string = "men cats houses venus carpet full"; for my $keyword ( keys %replacements ) { my $re = qr/\b$keyword\b/; $string =~ s/$re/$replacements{$keyword}/gi; } print "$string\n"; __OUTPUT__ women dogs homes mars rugs empty

Hope this helps. There are other similar idioms, and other different idioms that accomplish the same thing, but this one seems to be more or less what you're asking for.


Dave