my($text) = "(network) (test)_(ifcfg)"; my($first, $second, $third) = $text =~ /\((.*)\)/; #have this match all 3 and store them print "$first and $second and $third\n";