#!/usr/bin/perl -w use strict; print "This matches a US Zip code.\n"; print "Enter a test string here: "; my $myTestString = ; chomp($myTestString); if ($myTestString =~ m/\d{5} # Match five numeric digits (-\d{4})? # Optionally match a hyphen followed by four numeric digits /x) { print "There was a match which was '$&'."; } else { print "There was no match."; }