sub XML_elem { my $tag = shift; my @results; # return value my $attribs = shift @_ if( ref( $_[0] ) eq 'HASH' ); push @results, "<${tag}" . stringify_attribs( $attribs ) . ">"; if( @_ == 0 ) { # handle an empty element $results[0] =~ s|>$| />|; return @results; } foreach my $arg ( @_ ) { if( ref( $arg ) eq 'CODE' ) { push @results, map{ " $_" } $arg->(); # <--- ??? } else { push @results, ' ' . escape_ents( $arg ) } } push @results, "<\\${tag}>"; return @results; }