$ perl -e'while (<>) { printf "%03d %s", $., $_ }' file 001 foo 002 bar 003 baz 004 qux