#! /usr/bin/perl use strict; use warnings; my $string = "bla: foo,1234 bar,5678"; while ( $string =~ m{,(\w\w\w\w)}g ) { print "Match: $1\n"; }