if (my ($f, $l) = $line =~ /(.+)\s*\(\)\xA1\s*(.+\.txt)/) { $f =~ s/\s+$//; # notice \s+ and not \s*, too print OUT qq{$f\n}; }