#!/usr/bin/perl while (){ print if(m#\s+((\w+\s*)+)#g); } __DATA__ This is a test This is a (test) This is a (test123) this is a (123) This-is a test Just Another Perl Hacker