perl -ne 'substr ( $_,2,8 ) = " " && substr ( $_,15,5 ) = " " if /^AB/ ; print $_;' $1 > $1.tmp #### For some reason I end up with the following result: AB 12345 WORLD