Replace trailing whitespaces with pipe symbol using perl

I want to replace the whitespace with Pipe symbol to do a multiple pattern matching for the whole text "mysqld failed start" and same as for other text messages Below are the messages stored in a file seperate by whitespace

mysqld failed start 
nfsd mount failed 
rpcbind failed to start 

for each text i need to add the pipe symbol so that it will be easier to do mutliple search pattern similar to egrep.

expected o/p

mysqld failed start|nfsd mount failed|rpcbind failed to start

PLEASE USE CODE TAGS! The only trailing space that is visible in your 1st message is a space after the the last start and you haven't replaced it with a | character in the expected output.

Sorry for the confusion i don't want the pipe symbol at the end

@Kar_333
Your request incomprehensible...Do you understand "trailing whitespaces"? Please use code tags and place your request again

What you have shown us is still a single line of input and a single line of output with the 3rd and 6th spaces (which do not appear to be trailing spaces) changed to vertical bars. I still don't understand how to translate your example into a meaningful script. :confused:

Please edit your original post and insert appropriate CODE tags so we can see what you're trying to do.

Like this?
with bash/ksh93:

paste -sd'|' <(sed 's/[ \t]*$//' infile)

or with other shells not supporting process substitution:

sed 's/[ \t]*$//' infile|paste -sd'|' -

And with awk (with slight changes to RudiC's solution):

awk '{sub(/[ \t]*$/,"");printf("%s%s",(NR>1?"|":""),$0)}END{printf "\n"}' infile

With scrutinizer's edits of the original request and translating/guessing "whitespace" being <newline> instead of "space|tab|newline", I'd propose:

$ awk '{printf "%s%s", (NR>1)?"|":"", $0}' file
mysqld failed start |nfsd mount failed |rpcbind failed to start