use strict; use warnings; while(my $line = ) { chomp $line; my ($sQuery, $sSubject, $iLengthQ, $iLengthS, $iEndSinQ, $iBeginSinQ) = split(/\s+/, $line); #print "<$sQuery> <$sSubject> <$iEndSinQ> <$iBeginSinQ>\n"; my $sBefore = substr($sQuery, 0, $iBeginSinQ); my $sAfter = substr($sQuery, $iEndSinQ+1); # pipes added around inserted portion to make insertion point # a bit clearer in sample output. print "$sBefore|$sSubject|$sAfter\n"; } __DATA__ abc123def 123xxxx 9 7 5 3 0 2 1234xxxx YYYxxYZ0 8 8 5 4 3 4