in reply to getting a regex to return an array of matches?

Change this line i.e 'while' instead of 'if'
while ($filepieces =~ /SOME_REGEX/smg) {