#!/usr/bin/perl use strict; # change the below line to the file you are reading FROM (your junk fi +le) my $read_from = "test2.txt"; # Change the below line to where you want your neat phone numbers to b +e printed my $save_to = "saved.txt"; my %seen; open(FILE, '<', "$read_from") or die "Unable to open file.txt for read +ing, $!"; while () { #s /[\n|\r]//g; tr/0-9//cd; #print "Testing with $_, result is "; m/(1[-| ]?)?\(?(\d{3})\)?[-| ]?(\d{3})[-| ]?(\d{4})/; #m|(1-)?\(?(\d{3})\)?-?(\d{3})-(\d{4})|; my $areacode = $2; my $exchange = $3; my $line = $4; print "($areacode) $exchange-$line\n"; $seen{"$areacode-$exchange-$line"}++; } close(FILE); open(SAVED, '>', "$save_to") or die "Unable to open $!"; print SAVED "$_\n" for (sort keys %seen); close(SAVED);