while (<>) { if ($. == 2) { print ...image csv line... } else { print; } }