use warnings 'all'; use strict; use autodie; open my $input, '<', $ARGV[0]; open my $out, '>', $ARGV[1]; while (<$input>) { my ($before, $between, $after) = /(.*?.clothes|.something)(.*?)(\.m.*)/; print {$out} "$before $after"; }