#! /usr/bin/perl use strict; use warnings; my $in_file = 'input.txt'; my $out_file = 'output.txt'; my @result; open my $handle_in, '<', $in_file or die "$in_file: $!"; while ( <$handle_in> ) { # split (into 2 parts) at = (enclosed in optional whitespaces) # use the last part and store it in @result push @result, ( split( /\s*=\s*/, $_, 2 ) )[-1]; } close $handle_in; # remove line breaks from array elements chomp @result; open my $handle_out, '>', $out_file or die "$out_file: $!"; # print elements (ignore undefined and empty ones) print $handle_out join( '/', grep { defined && length > 0 } @result ) or die "$out_file: $!"; close $handle_out or die "$out_file: $!"; __END__