Try this, but your question is a little unclear. Please give an exact input and output test case, not a partial one.
#!/usr/bin/perl # http://perlmonks.org/?node_id=1190966 use strict; use warnings; $_ = do { local $/; <DATA> }; s/^(\w+(?:[-_]\d+)?)\n(?=.*\1\b)//gm; print; __DATA__ Text_1 sample-text file Text_1 matching the 1st line matching the last line Text text_1 text-2 sample-text file text-2 matching the 1st line matching the last line text_1 text-2 text sample-text file text matching the 1st line matching the last line
In reply to Re^3: match a word and delete last line
by tybalt89
in thread match a word and delete last line
by ArifS
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |