#!/usr/bin/perl use strict; use warnings; open FILE1,"input.txt"; open FILE2,">>output.txt"; foreach my $line ( ) { $_= $line; s/^HDR.{47}//; s/\KFTR.{27}//; print FILE2 $_; } close FILE1; close FILE2;