#!/bin/perl -w use strict; my %hash; while( <>) { # note: the left part should be just one character $hash{$2}= $1 if( m/^\s*(.)\s*::=\s*([^\s]*)\s*$/); } while( my($key, $value)= each %hash) { print "/$key/ ::= /$value/\n"; } #### #!/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"; }