#!/usr/bin/perl -w use strict; my @lines = (); while( my $line = <> ) { next if $line =~ /^\s*#/; next if $line =~ /^\s*$/s; chomp $line; push @lines, $line; } print((join ";", @lines), "\n");