open FILE, '<', ... my @numbers; while( } { push @numbers, m[^[ ]*[0-9]+[ ]*$] ? 0+$_ : m[^[ ]*[0-9A-Z]+[ ]*$]i ? hex() : die "Bad number at $."; } ## That hex() would do all of that for you and more is irrelevant