use strict; use warnings; my $file = shift @ARGV; open (my $fh1, $file) or die "Can't open file \"$file\", $!"; my @txt = <$fh1>; close $fh1; my $newtext = '"seq_name" "sequence.V6.0"'; my $i; for ($i=0; $i <= $#txt; $i++) { last if $txt[$i]=~ m/"StrCatDone" "1"/; #print $txt[$i]; } $txt[++$i]="$newtext\n"; open (my $fh2,">$file") or die "Can't open file \"$file\", $!"; print $fh2 @txt;