Find the number closest to 0, breaking ties in favor of positive numbers
A bad example

Perl is a language in which the shortest code is usually not the best code.  For example, this short program accomplishes the task:

print((sort {abs($a)&lt;=&gt;abs($b) || $b&lt;=&gt;$a} (split ' ',&lt;&gt;)[0..&lt;&gt;-1])[0] // 0)


Not only is it hard to read, it's also algorithmically inefficient (because sorting is O(n log n) rather than O(n)).  I don't recommend writing code like that.

Critique

You should use more whitespace.  It won't make your code look any less clever, nor will it make your code run any slower.

You can safely dispense with chomp(), as Perl will naturally disregard the trailing newline when interpreting the string as a number.  You could probably write &lt;&gt; instead of &lt;STDIN&gt;, unless you insist on reading only from standard input.

Counting loops are clumsy in Perl.  When possible, opt for higher-level list-processing techniques.  In this case, I recommend List::Util::reduce.

A possible solution

In Perl, there are usually many possible ways to solve a problem.  Here's one short solution that is O(n), but avoids being the shortest possible solution.  I'll let you figure out how it takes advantage of the &lt;=&gt; operator.

use List::Util qw(max reduce);
use strict;

my $n = &lt;&gt;;
my @temps = (split ' ', &lt;&gt;)[0 .. $n - 1];
print((reduce { ($a, max($a, $b), $b)[1 + (abs($a) &lt;=&gt; abs($b))] } @temps)
       // 0);


The special case of $n == 0 can be handled using a // logical defined-or operator.  A || logical or operator would also happen to work, but it wouldn't be as appropriate.

Since the @t is meant to represent temperatures, renaming it to @temps would make the code less cryptic.