in reply to shouldn't this work?

There are no stars in your input! And your script should work fine if there were.
With a little code cleanup it becomes:
my $output; while( my $line = <DATA> ) { # get rid of line terminator: chomp $line; next unless $line; # Get rid of line numbers: $line =~ s/^N[0-9]{2}\ //; # Replace * and the beginning of the line with !: $line =~ s/^\*/!/ and print $line and next; # Keep any numbers prefixed with X,Y or Z.: $line =~ s/(X|Y|Z)([0-9.-]+)/ $2/g; # Throw the rest away: $line =~ s/[A-Z][0-9.+-]+//g; print $line; } ...


T I M T O W T D I