#!/usr/bin/perl -w use strict; my %commas = ( 'notalot' => 1, 'england,rugby' => 1, 'chicken,egg,duck,feet' => 1, ',southampton' => 0, 'bristol,' => 0, 'iran,,canada,france' => 0, ); foreach my $key (keys %commas) { unless (($key =~ /^,|,,|,$/)) { print "PASS"; } else { print "FAIL"; } print ": $key\n"; } #### FAIL: bristol, PASS: notalot PASS: england,rugby FAIL: iran,,canada,france PASS: chicken,egg,duck,feet FAIL: ,southampton