#!/usr/bin/perl -w -i.bak use strict; while (<>) # Loop over lines of file { next unless ($. > 2); # Ignore first two lines s/do my/replacement/ if ($. == 3); print $_; }