for (@$sur) { my $firstrow = join '<-->', @{$_}{qw/one two four/}; $hash1{$_->{'three'}} .= $hash1{$_->{'three'}} ? '####'.$_->{'four'} : $firstrow; }