#!/usr/bin/perl use Modern::Perl; use Data::Dumper; #945627 Workaround if the distinction among elements in each data # segment need not be retained; if retention # is required, read DATA into a HoA with the # separator-and-its-following-digit(s) as keys. say "\n\t \$/ is a string, not a regex," . "\n\t so, using an input_separator without any regex metachar \n"; $/ = "FOO"; my @newarr; my @arr = ; for my $item(@arr) { $item =~ s/\n//sg; if ( $item =~ /^\d+(.+?)(?:FOO)*$/s ) { my $out = $1; push @newarr, $out; } else { say "\t Disgarding $item (ie, \$arr[1])"; # discarding the initial "FOO" in $arr[1] } } print Dumper @newarr; =head OUTPUT $/ is a string, not a regex, so, using an input_separator without any regex metachar Disgarding FOO (ie, $arr[1]) $VAR1 = 'abcdefghi'; $VAR2 = 'jkl-123-'; $VAR3 = 'mnopqrstu'; $VAR4 = 'vwxyz'; =cut __DATA__ FOO0 abc def ghi FOO1 jkl -123- FOO2 mno pqr stu FOO3 vwxy z