#!/usr/bin/perl -w use strict; $/=undef; my $data = ; my @text = ($data =~ /(Nullam.+(?:augue|libero)\.)/g); print @text; #__prints: #Nullam quis augue. #### $/=undef; my $data = ; my @text = ($data =~ /(Nullam\b[^.]+(?:augue|libero)\.)/g); @text = map{tr/\n/ /;$_}@text; print join("\n",@text),"\n"; #print join(" ",@text); #alternative to put a space after the period.