... # add this line my $maxval = 0; foreach (@array) { $maxval = $_ if $_ > $maxval; # and populate as needed here print $_, "\t"; $counter ++; if ($counter % 4 == 0) { print "\n"; } } # then include the value in your final print statement print "The largest element is: $maxval\n"; #### use strict; use List::Utils qw/max/; # add this line ... # rest of your code is unchanged # and then use the function in your final print statement print "The largest element is: " . max(@array) ."\n";