http://www.perlmonks.org?node_id=598542


in reply to Complex Splitting

This should do the trick - Its only tested on your string though...
#!/usr/bin/perl use strict; use warnings; my $string = "ABC[GHI]XYZ"; my @array; splitstring($string); push @array, split//, $string; print "$_ " for sort @array; sub splitstring { return unless ( $string =~ /.*\[\w+\].*/ ); if ( $string =~ /.*(\[(\w+)\]).*/ ) { my $remove = $1; my $str = $2; print "rem = $remove\n str = $str\n"; push @array, $str; $string =~ s/\Q$remove\E//; } splitstring($string); }
UPDATE
I substututed the string with [987]ABC[GHI]XYZ[dfg] and that works as well.

regards

Ted
--
"That which we persist in doing becomes easier, not that the task itself has become easier, but that our ability to perform it has improved."
  --Ralph Waldo Emerson