in reply to Take last instance of a string

Another solution, reading from a file line by line, and remembering the last position where the string was seen. After having read the whole file, seek back to the position and extract the text.

#!/usr/bin/perl use warnings; use strict; open my $FH, '<', shift or die $!; my $pos; while (<$FH>) { $pos = tell $FH if -1 != index $_, 'Significant Accounting Policie +s'; } if (defined $pos) { seek $FH, $pos, 0; print while <$FH>; }

Update: simplified, as you don't want to print the line containing the string.

($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,