#!/usr/local/bin/perl while(<>) { $m = 0 ; while (s/\(([^)]+)\)// ) { print $1, " " ; $m ++ ; } print "\n" if($m) ; }