in reply to extract the tail from a string (with new lines) containing a substring

I don't understand what you're doing. If you execute the Perl statement
    my $out = qx/grep -A 3 -B 3 xxx  file-B >> file-A/;
then  $out will be empty because output is re-directed to file-A.

c:\@Work\Perl\monks\jjmoka>dir Volume in drive C is Acer Volume Serial Number is 9480-355B Directory of c:\@Work\Perl\monks\jjmoka 01/20/2020 03:28 PM <DIR> . 01/20/2020 03:28 PM <DIR> .. 01/20/2020 03:22 PM 95 file-B 1 File(s) 95 bytes 2 Dir(s) 76,795,633,664 bytes free c:\@Work\Perl\monks\jjmoka>type file-B one two three four five six seven eight nine ten eleven twelve thirteen fourteen c:\@Work\Perl\monks\jjmoka>perl -wMstrict -MData::Dump -le "my $out = qx/grep -A 2 -B 2 four file-B >> file-A/; dd $out; " "" c:\@Work\Perl\monks\jjmoka>type file-A two three four five six -- twelve thirteen fourteen
This is under Win7, Perl 5.8.9.


Give a man a fish:  <%-{-{-{-<