for (@$matrix_ref) { $html_str .= cell_wrap( $_->[0] eq $key ? $_->[2] : (@{$_}[0..2]) ); $key = $_->[0]; }