in reply to indirectly accessing variable

If I understand correctly, you want to call that like, writeBasicTag( 'year' ); , and produce XML with data from $year. You are trying to do it with symbolic references, which will work under no strict 'refs'; , but is not best practice. If you change 'XXX' to '$$tag', you'll get what you want, but there is a better way.

The rule of thumb is: When you want to use symrefs, use a hash instead, my %stuff = ( year => '1999', foo => 'bar', baz => 'quux', ); Now there is no reason to restrict yourself to single arguments. You ought to be able to call your sub for a list of tags, so let's rewrite to loop over @_,

sub writeBasicTag { for (@_) { $writer->startTag($_); $writer->characters($stuff{$_}); $writer->endTag($_); } 1; }
Note that there is a closure on %stuff (as well as $writer), so attention must be paid to scoping and initialization.

Update: ++The Mad Hatter for typo correction.

After Compline,
Zaxo