Each time Perl sees an <test> it reads another line from 'test'. There is no problem with using =~ in conjunction with your <test> construct...but it does cause another read from test. I'm not sure what you were intending or hoping the line $_ =~ <test> was supposed to do. Can you say what you were thinking?
In case you're wondering, the other read occurs in your loop control line while(<test>).
To keep it from reading twice but to still do what it looks like you're wanting to do you can use a construct like:
while (<test>) [ chomp; s/(th)/TH/gi; print "$_\n"; } close (test);
Several other monks that have answered your inquiry show this and I think it is the right answer. But since I'm not sure what you intended with the line $_ =~ <test>, I'm not positive that deleting the line really results in what you were intending.
In reply to Re^3: Why are lines being skipped in output?
by ack
in thread Why are lines being skipped in output?
by negzero7
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |