use Data::Dumper; $string = "sp Hello there sp \n Hey hey sp How are you? sp I need a dsp chip and have a spelling test."; @results = $string =~ m/\bsp\s+(.*?)\s+sp\b/g; print Data::Dumper->Dump([\@results]); __OUTPUT__ $VAR1 = [ 'Hello there', 'How are you?' ];