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
In reply to Re: The regular expression in perl one liner not giving the expected output
by jwkrahn
in thread The regular expression in perl one liner not giving the expected output
by perladdict
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |