# Keeps newlines. my $str = q~ ... ~; my @fetch = grep { /test/ } ($str =~ m#(.*?)#sxgi); print(scalar(@fetch), "\n"); print join("\n---\n",@fetch); #### # Removes newlines. my $str = q~ ... ~; my @fetch = map { local $_=$_; s/\n+//g; $_ } grep { /test/ } ($str =~ m#(.*?)#sxgi); print(scalar(@fetch), "\n"); print join("\n---\n",@fetch);