#!/usr/bin/perl use strict; use warnings; use Regexp::Common; while () { chomp; my $zip_match = 0; if (/$RE{zip}{US}{-keep}/) { $zip_match ++; $zip_match ++ if $6; } printf "Value %d for zip code '%s'\n", $zip_match, $_; } __DATA__ 6789 12345 12345-6789 Value 0 for zip code '6789' Value 1 for zip code '12345' Value 2 for zip code '12345-6789'