The goal of this exercise is to practice string handling. You basically need to use functions index, substr and split. In the second phase, its sufficient to use the sort function. Task: Produce a sorted set of virt. - occ. orbital energy differences, given following input: The electronic state is 1-SGG. Alpha occ. eigenvalues -- -0.27448 -0.27448 -0.26801 -0.26801 -0.26335 Alpha occ. eigenvalues -- -0.25992 -0.25992 -0.25881 -0.25881 -0.25630 Alpha occ. eigenvalues -- -0.25257 -0.25257 -0.25129 -0.24488 -0.24084 Alpha occ. eigenvalues -- -0.23960 -0.23960 Alpha virt. eigenvalues -- -0.22118 -0.16758 -0.09795 -0.06680 -0.06680 Alpha virt. eigenvalues -- -0.05189 -0.05189 -0.04384 -0.02944 -0.02944 Alpha virt. eigenvalues -- 0.00231 0.00231 0.01770 0.03559 0.03611 Alpha virt. eigenvalues -- 0.03742 0.03742 0.06332 0.07490 0.07490 Alpha virt. eigenvalues -- 0.07566 0.08138 0.08138 0.09503 0.09503 Alpha virt. eigenvalues -- 0.10922 0.11238 0.11238 0.13825 0.13825 Alpha virt. eigenvalues -- 0.14176 0.16297 0.16297 0.17893 0.18998 Basically, go through *all* combinations of (occ, virt) energy pairs, form the list of differences, and sort it. The first item should be: 0.23960-0.22118= .01842 Pay attention that sort @list uses text comparison. use sort { $a <=> $b} for the numeric one.