print "$array[-1]\n"; # If you mean last element of array my $last = keys %hash; my $counter = 0; for my $key ( keys %hash ) { $counter++; print "$hash{$key}\n" if $counter == $last; } # If you mean determine if this is last item in loop #### use Scalar::Util 1.10 'looks_like_number'; use List::Util 'max'; my @numbers; while ( ) { chomp; push @numbers , $_ if looks_like_number( $_ ); } print max(@numbers), "\n";