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