#!/usr/bin/perl # full script the following one liner: # $ echo -e "abc\ndef\nghi\n" | perl -wlne '! /def/ and print "$_";' # abc # ghi use strict; use warnings; use diagnostics; my $C; my $B = ""; my $A = "abcdef fhijkl mnopqr "; while ( $A =~ m{(.+)}g ) { $B .= "$1\n" unless $1 =~ /ijk/; # $B .= "$1\n" unless $1 =~ /xyz/; } print "\$B = \n$B\n"; $B = ""; while ( $A =~ m{(.+)}g ) { $C = $1; $B .= "$C\n" if $C =~ /ijk/; } print "\n\$B = \n$B\n";