Just wrap in a queue where you can add more things to the front. It does mean you
will have to split some things into two parts, but still is just a fairly simple change.
#!/usr/bin/perl
use strict; # https://perlmonks.org/?node_id=11144894
use warnings;
my @functionqueue = @ARGV ? @ARGV : qw( test1 test2 test1 ); # FIXME
while( @functionqueue )
{
for ( shift @functionqueue ) {
/test1/ && do {
print "test1 stuff\n";
};
/test2/ && do {
print "test2 stuff\n";
unshift @functionqueue, qw( test1 secondpartof2 );
};
/secondpartof2/ && do {
print "secondpartof2 stuff\n";
};
}
}
Outputs:
test1 stuff
test2 stuff
test1 stuff
secondpartof2 stuff
test1 stuff