#!/usr/bin/perl use strict; use warnings; my %hash=(); # input my $inputfile = 'nv.txt'; open IN, '<',$inputfile or die "Could not open $inputfile : $!"; while () { my ($key, $val) = split (/:/,$_,2); $hash{$key} .= $val; } # output for my $key (keys %hash){ my $outputfile = "output_$key"; $outputfile =~ s{/}{-}g; print "Writing to $outputfile\n"; open OUT,'>',$outputfile or die "Could not open $outputfile : $!"; print OUT $hash{$key}; close OUT; } __DATA__ test/right/case1:12: //comment test/right/case1:344: //comment test/wrong/case3:123: //comment