my @test_data_2 = ( 'para', [ ['none', 'The quick brown '], ['bold', 'fox'], ['none', ' jumped '], ['ital', 'over'], ['none', ' the lazy '], ['bold', 'dog'], ['none', '.'] ] ); sub build_HTML { join "" => map { (ref($_->[1]) eq "ARRAY") ? $handlers{$_->[0]}->(build_HTML(@{$_->[1]})) : $handlers{$_->[0]}->($_->[1]) } ref($_[0]) ? @_ : ([ @_ ]); } print build_HTML(@test_data_2);