use strict; use warnings; sub do_something { print '{', $_[0], "}\n" } local $/ = ' '; while () { s/\n/ /; # replace end-of-line with space my @a = split(' '); # split line at spaces do_something($_) for @a; } __DATA__ 1 2 3 4 5 0 6 7 8 9 10 0