my $target = 'this is a test of the servise'; if ($target =~ /test/) { $target =~ s//test2/; } if ($target =~ /nothing/) { $target = s//null/; } else { $target =~ s//foo/; } #### [....] If the pattern evaluates to the empty string, the last successfully executed regular expression is used instead. [....]