$ perl -MO=Deparse,-p -e"open $fh[$_],'>','split.'.$_ for 0..9;" -nle"print {$fh[substr $_,3,1]} $_" big.log BEGIN { $/ = "\n"; $\ = "\n"; } LINE: while (defined(($_ = ))) { chomp($_); open($fh[$_], '>', ('split.' . $_)) foreach (0 .. 9); print({$fh[substr($_, 3, 1)];} $_); } -e syntax OK