sub render { my ($tag, $attr, $content) = @_; # hier entsprechend GetPic, GetAudio etc. implementieren } sub parse { my ($text) = @_; my $output = ""; my $stack = []; while (length $text) { if ($text =~ s/^\[(pic|audio|infobox)=//) { my $name = $1; # tag my $attr = ""; if ($text =~ s/^([^\[\]]+)//) { $attr = $1; } push @$stack, [$name, $attr, ""]; } else { my $out; if ($text =~ s/^\]//) { # closing tag my $last = pop @$stack; my ($name, $attr, $content) = @$last; $out = render($name, $attr, $content); } else { # text if ($text =~ s/^([^\[\]]+)//) { $out = $1; } } if (@$stack > 0) { $stack->[-1]->[2] .= $out; } else { $output .= $out; } } } return $output; } my $output = parse($data);