http://www.perlmonks.org?node_id=206278


in reply to A new question from the front line

I'd probably do it more or less the same way you did; but for perversity's sake, here's another possibility:

perl -ple 'BEGIN{$/="energy";<>;$.--}/.+/;$_=$..$&' filename

perl -pe '"I lo*`+$^X$\"$]!$/"=~m%(.*)%s;$_=$1;y^`+*^e v^#$&V"+@( NO CARRIER'