my $tag; if($change){ #contruct modified tag # Wow this is ugly $tag = '<'.$token->[1].' '.join(' ',map({"$_ = '".$token->[2]{$_}."'"} keys(%{$token->[2]}))).'>'; } else { #output original tag # This is nice $tag = $token->[0] eq "T" ? $token->[1] : $token->[-1]; }