perl script help

Hello Friends, How can I remove the last two values of this line using perl script?

John Carey:507-699-5368:29 Albert way, Edmonton, AL 25638:9/3/90:45900

The result file should look like this:
John Carey:507-699-5368:29 Albert way, Edmonton, AL 25638

my $example1="John Carey:507-699-5368:29 Albert way, Edmonton, AL 25638:9/3/90:45900";

if ($example1 =~ /(.*)(.{2}$)/ )
{
print "$1";
}
else
{
print "Not Matched";
}

fly2matrix: I have a lot of data in the file with the same structure. The file look like the following... The script should remove the last two fields of each line in the file.

info.txt
John Carey:507-699-5368:29 Albert way, Edmonton, AL 25638:9/3/90:45900
Brian Jonathan:567-690-5668:98 state way, Newyork, NY 25638:9/3/70:55921
Jim cary:663-600-4660:78 state way, Minneapolis, MN 56892:6/8/80:52589

Try this one : perl -pi.bak -e "s#(.{2}$)##g;" info.txt

This is one liner perl code ...

Here's one way -

$
$
$ # show the content of the input data file "info.txt"
$
$ cat info.txt
John Carey:507-699-5368:29 Albert way, Edmonton, AL 25638:9/3/90:45900
Brian Jonathan:567-690-5668:98 state way, Newyork, NY 25638:9/3/70:55921
Jim cary:663-600-4660:78 state way, Minneapolis, MN 56892:6/8/80:52589
$
$ # remove the last two fields from each line of "info.txt"
$
$ perl -plne 's/(:[^:]+){2}$//' info.txt
John Carey:507-699-5368:29 Albert way, Edmonton, AL 25638
Brian Jonathan:567-690-5668:98 state way, Newyork, NY 25638
Jim cary:663-600-4660:78 state way, Minneapolis, MN 56892
$
$

If you want to do inline edits -

$
$
$ # back up "info.txt" into "info.txt.bak" and then remove the last two fields from each line of "info.txt"
$
$ perl -i.bak -ple 's/(:[^:]+){2}$//' info.txt
$
$ # confirm that the file "info.txt" was actually updated
$
$ cat info.txt
John Carey:507-699-5368:29 Albert way, Edmonton, AL 25638
Brian Jonathan:567-690-5668:98 state way, Newyork, NY 25638
Jim cary:663-600-4660:78 state way, Minneapolis, MN 56892
$
$ # confirm that the file "info.txt" was backed up into "info.txt.bak" before the update
$
$ cat info.txt.bak
John Carey:507-699-5368:29 Albert way, Edmonton, AL 25638:9/3/90:45900
Brian Jonathan:567-690-5668:98 state way, Newyork, NY 25638:9/3/70:55921
Jim cary:663-600-4660:78 state way, Minneapolis, MN 56892:6/8/80:52589
$
$
$

HTH,
tyler_durden

Thanks Guys. It worked