in reply to The regular expression in perl one liner not giving the expected output

The -p switch on the command line tells perl to read one line at a time therefore the contents of $2 are always empty because there is nothing after the newline for it to match.    You need something like:

perl -lpe'$\ = /^usmat/ ? " phani " : " raj\n"' p1