#!/usr/bin/perl use strict; use warnings; my @tests = ("Server list (Win2K/Win2003/XP) 6.26.5.1.5", "Server list 6.26.5.1.5"); for (@tests){ if (m/([^(\d]+) ((?:\([^)]+\))?) (.*)/x){ print "$1|$2|$3\n" } else { print "No match for $_\n"; } } __END__ Server list |(Win2K/Win2003/XP)| 6.26.5.1.5 Server list ||6.26.5.1.5