After fixing your scope issue, your code is fine as it is, I just wanted to introduce you to List::Util and here-docs.

List::Util has functions useful when operating on arrays, specifically the sum, min and max functions, which could replace your foreach loop.

Here-docs are useful when you want to print a multi-line string, you write output much like you would in a plain text editor, literal horizontal and vertical white spaces are honored without the need for escape sequences, also you have the ability to interpolate variables. In my opinion it increases clarity.