@array = ( "foo bar", "bar foo" ); @array2 = ( "foo", "bar" ); $string = "there is a foo bar and a bar foo and also foo and bar."; print "string before - $string\n"; $swapString = join ("|", @array, @array2); print "swapString 1 - $swapString\n"; $string =~ s/($swapString)/$1<\/B>/gi; print "string after first - $string\n"; #### string before - there is a foo bar and a bar foo and also foo and bar. swapString 1 - foo bar|bar foo|foo|bar string after first - there is a foo bar and a bar foo and also foo and bar. #### $swapString = join ("|", sort { length($b) <=> length($a) } @array, @array2);