use warnings; use strict; open my $fh, '+>', 'output.txt' or die("Can't open the damn file!: $!"); open FILE, 'c:/aperlphone/myphonelist.txt' or die $!; while(my $line == 'FILE') # semi-colon removed(run1) & (run2)equity test to '==' { # extra empty line removed: HazNav (not an error) chomp $line; my ($name, $num) = split(/\s+(?=\d)/, $line); # missing semi-colon inserted (run 1) # some lines have whitespace after the num $num =~ s/\s+//g; if ($num =~ /^\d{4}$/){ $num = "(333)-447-$num"; } elsif ($num =~ /^\d{3}-\d{4}$/){ $num = "(333)-$num"; } print $fh "$name $num\n"; }