in reply to Null scalars in array

It looks like you have a string containg some words (or numbers) between "foo" and "bar". The words themselves are separated with spaces, so

foo a b cd efg bar
is what you want to search for, I assume.

The regular expression you mention expects "foo" and "bar" to occur more than once, so it might not be the regexp you are looking for. You could use two steps: first, find everything between "foo" and "bar", then split that into separate words or numbers. The code would then be:

my @matches; if ($data =~ m/foo (.*) bar/) { # everything between foo and bar go +es into $1 @matches = split(' ', $1); # split on whitespace }

I cannot think of a regexp that does it in one go, so I welcome smarter solutions.