my $string = ''; # output string open FILE, ") { chomp; s/^N\d+ //; # strip line numbers if (/^\*/) { # comment s/^\*/!/; $string .= $_; } else { # other while ($_ =~ /[x-z]/([\d.+-]+)/ig) { $string .= " $1"; } } } print $string;