#! perl use strict; use warnings; my %exclude_left = map { lc $_ => undef } qw( web 2 ); my %exclude_right = map { lc $_ => undef } qw( program call ); my $z = 'Web-developer, perl-program, explicit-element, function-call, 2-x speed.'; my @phrases = split /(\s+)/, $z; for (@phrases) { # 1 2 3 <-- capture groups if (/ ( (\w+) - (\w+) ) /x) { my ($phrase, $left, $right) = ($1, $2, $3); s/$phrase/$right-$left/ unless exists $exclude_left {lc $left } || exists $exclude_right{lc $right}; } } print '|', join('', @phrases), "|\n"; #### 17:36 >perl 1667_SoPW.pl |Web-developer, perl-program, element-explicit, function-call, 2-x speed.| 17:36 >