$sign=""; if($_<0) { $_=-$_; $sign="-"; } ...and at the end print $sign,@a