#!/bin/perl -w use strict; my %hash; while( <>) { my($key, $value)= m/^\s*(.)\s*::=\s*([^\s]*)\s*$/; $hash{$key} ||= []; # create an array ref if needed push @{$hash{$key}}, $value; # add to the array } while( my($key, $values)= each %hash) { # the values are in @{$values} print "/$key/ ::= /", join( '/', @{$values}), "/\n"; }