use strict; use Template (); use Scalar::Util qw( looks_like_number ); sub fmt_currency { my( $txt ) = @_; return $txt unless looks_like_number( $txt ); if( $txt < 0 ) { $txt = '(' . abs( $txt ) . ')' } else { ## maybe wrap $txt with a pos span . . . } return $txt; } my $t = Template->new( FILTERS => { fmt_currency => \&fmt_currency }, ## ... ); my $data = { qw/foo 1.23 bar -3.45 baz quux/ }; my %tmpl_src = <process( \$tmpl_src, $data, \*STDOUT ); exit 0; __END__ 1.23 (3.45) quux