This works for me... # sample data my @tags = qw(K001900 L001234 GP001675); my @prefixs = qw(SP 8 L K GP TP MP);
# join them with pipes for use in the regex my $prefix = join('|', @prefixs); # match prefix against each tag, seprate the parts. # the "o" switch cause the regex to only compile once. # the split tags go back into the @tag array. my @tags = map {/^($prefix)(.*)$/o;{PRE=>$1,NUM=>$2}} (@tags); # this print out the prefix/number pairs foreach my $tag (@tags) { print "PREFIX: ", $tag->{PRE}, "\n"; print "NUMBER: ", $tag->{NUM}, "\n"; print "\n"; } Something like that? Rob -----Original Message----- From: Mike(mickako)Blezien [mailto:[EMAIL PROTECTED]] Sent: Wednesday, August 14, 2002 2:44 PM To: Perl List Subject: Better regrex method Hello, I'm working on a project where I need to split various tag numbers, from a standard set of prefixes, entered into a form and check the number against a database. A sample test code that works, but was wondering if there's a better way to utilize the regrex of this code: # @tags similuate the tag numbers entered into a form, multiple numbers my @tags = qw(K001900 L001234 GP001675); # @prefixs are a pre-determined set of prefixes used. my @prefixs = qw(SP 8 L K GP TP MP); my($tagid,$tnum); print header('text/html'); while(my $prefix = <@prefixs>) { foreach $tagid (@tags) { if ($tagid =~ m!^$prefix!) { $tagid =~ s!^$prefix!!; print qq|Prefix: $prefix - Number: $tagid<br>|; # Results: Prefix: K - Number: 001900 # ...etc } } } My questions is, is there a better way to separate the prefix from the number ?? Any suggest would be much appreciated. TIA, -- Mike(mickalo)Blezien =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Thunder Rain Internet Publishing Providing Internet Solutions that work! http://www.thunder-rain.com Bus Phone: 1(985)902-8484 Cellular: 1(985)320-1191 Fax: 1(985)345-2419 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]