see
perlvar:
The Perl syntax error message from the last eval() operator. If $@ is the null string, the last eval() parsed and executed correctly (although the operations you invoked may have failed in the normal fashion). (Mnemonic: Where was the syntax error ``at''?)
Warning messages are not collected in this variable. You can, however, set up a routine to process warnings by setting $SIG{__WARN__} as described below.
Also see Error Indicators.
In that sense, $@ is a scalar and therefore, looping about a scalar makes no sense and you can replace that code with:
print $@ if $@;