open FILE, "/home/btobin/data.txt" || die "Unable to Open: $!"; while () { if ($_ =~ "Perl") { $check = "$_"; } } close FILE; open FILE2, ">>/home/btobin/data2.txt" || die "Unable to Open: $!"; print FILE2 "$check\n"; close FILE2;