my $output; while( my $line = ) { # get rid of line terminator: chomp $line; # Get rid of line numbers: $line =~ s/^N[0-9]{2}\ //; # Replace * and the beginning of the line with !: $line =~ s/^\*(.*)/!$1/ and print $line and next if $line; # Keep any numbers prefixed with X,Y or Z.: $line =~ s/(X|Y|Z)([0-9.-]+)/ $2/g if $line; # Throw the rest away: $line =~ s/[A-Z][0-9.+-]+//g if $line; open print $line; } __DATA__ O1407!SILH 5B NECK PROFILE STD.> N1! 11-14-01 N2!T1 3/4" ENDMILL N3! OUTPUT IN ABSOLUTE N4L0200 N5! SUB NUMBER: 2 N6G90G0X11.108Y-18.25 N7G1Z-1.13F80. #### $file = "file.txt"; open (FILE, "$file"); my $output; while( my $line = )... etc.