my $concat = "good times and fun (times) and bad (times)"; for my $string ('good times', 'bad times', 'fun (times)') { # if the index function returns -1, it is not a substring if (index($concat, $string) == -1) { $concat .= " and $string"; } } print $concat . "\n";