#!/usr/bin/perl -w use strict; my $str = '129-129A & B-131 NORTH AV'; print "\nDon't check for undefined matches\n"; while ($str =~ m[(.*?)(?:\s*([&/+-])\s*|\s+)]g){ print "\$1='$1'\t\t\$2='$2'\n"; } print "\nCheck for undefined matches\n"; while ($str =~ m[(.*?)(?:\s*([&/+-])\s*|\s+)]g) { my $one = "undef"; my $two = "undef"; $one = $1 if defined $1; $two = $2 if defined $2; print "\$1='$one'\t\t\$2='$two'\n"; } print "\nPseudo Split\n"; my @b = ($str =~ m[(.*?)(?:\s*([&/+-])\s*|\s+)]g,$'); foreach (@b) { $_="undef" unless defined $_; print "'$_',\n"; }