while (<>) { chomp if /^CLI\b/; print; } # or without all those default variables while (my $line = <$FILEHANDLE>) { chomp($line) if $line =~ /^CLI\b/; print $line; }