in reply to Break a file into seperate files based on string match

#!/usr/bin/perl # http://perlmonks.org/?node_id=1206430 use strict; use warnings; use Path::Tiny; my %parts; while(<DATA>) { /^(.*) : (\S+)$/ and push @{ $parts{"$2.txt"} }, "$1\n"; } for my $filename (sort keys %parts) { path($filename)->spew( $parts{$filename} ); } __DATA__ test/foo/bar : tag1 test/abc/xyz : tag1 test/def/abc : tag2 test/bar/foo : tag2 test/dummy/foo : tag1