my $query = undef; if ($query =~ /^(([\w\d\-\_]+)[:,]|)(.*)$/) { # we get here! print "$`|$1|$2|$3|$4|$'|$query|"; } else { exit; } __END__ ||||||| C:\>perl -v This is perl, v5.8.4 built for MSWin32-x86-multi-thread #### C:\>perl -le"print 1 if undef =~ //" 1 C:\>perl -le"print 1 if undef =~ /|/" 1 C:\>perl -le"print 1 if undef =~ /blahblah|/" 1