use warnings; use strict; use autodie; open INF, "<$file"; while (){ if(/First line of text$/ ... /in the third line I have (\d*\.\d*)$/) { push @array, $1 if $1; } }