#!/usr/bin/perl -w use strict; use warnings; my %CpmRC; while () { %CpmRC = /^(\d+)\W\d+\W\d+\W(\d+)\W\w+/; } while (my ($key, $value) = each(%CpmRC)) { print "$key,$value\n"; # Print contents of the hash } __DATA__ 030 003 1234567 4403 comments 031 003 1234567 4404 comments 032 003 1234567 4405 comments OUTPUT: 032,4405