in reply to find & replace a string in perl

Another one (using Regex positive lookahead)

perl -pi -e 's/(?=.*\btest\b)/#/' fileName