$a = 'a.txt'; open(IN,$a) || die "cannot open $a for reading: $!"; $b = 'time.txt'; open(OUT,">>$b") || die "cannot create $b: $!"; while () { # read a line from file $a into $_ #print OUT $_; if (/returns \d{1} \(in \d{1}.\d{6} secs/) { print OUT ?? ; } } close(IN) || die "can't close $a:$!"; close(OUT) || die "can't close $b:$!";