in reply to Regular Exp. in foreach loop Help!

I believe I understand your confusion. Output happens not according to what comes first in your code, but what is executed first in your code. When you loop over an array you will process each element in turn. So you get the first element's output, the second element's output, etc. This has everything to do with how your data is organized, not your code.

If you wish to reorder your output you need to reorder your data. For that you can collect data into data structures as you go through the array. Then process the data structures at the end.

Here are some further points of potential confusion that I see in your code.

Here is some code that might do something more like what you want.
my @account = qw( 34765-22333-333489-99867-22340-23456-3229 XLM8876 AMP7765 WQP22349 ); my @account_starting_with_digit; my @account_starting_without_digit; for my $checked (map {split /-/, $_} @account) { if ($checked =~ /^\d/) { push @account_starting_with_digit, $checked; } else { push @account_starting_without_digit, $checked; } } print "*" . (join " ", @account_starting_without_digit) . "*<br>\n"; print "-" . (join " ", @account_starting_with_digit) . "-<br>\n";
If you wish further help I strongly suggest that in addition to showing your code (which is a good step) you actually show the output you were hoping that your code would produce but didn't. This would greatly clarify what you want, particularly if it is very different from what your code does.