my $str = "Red and Blue"; my $sbs = "red/green"; my ($search, $replace) = split(/\//, $sbs); $str =~ s/$search/$replace/si; print "$str\n";