my $pref = 'pref1'; open(FH, "+< $FILE") or die "Error opening $FILE: $!\n" my @lines = ; seek(FH,0,0); my $count = 0; foreach my $l ( @lines ) { $count++; # Skip lines not matching $pref if( $line !~ /^$pref/ ) { next; } my ($pref, $num) =~ /^(.*?)\t(.*?)$/; $num = 1; $lines[$count] = "$pref\t$num\n"; } print FH @lines; truncate(FH, tell(FH)); close(FH);