#!/bin/sh INFILE=test.in # get number of lines not matching "^#" (-v inverses the results) non_comment_lines=$(cat $INFILE | grep -cv "^#"); if [ 0 -lt $non_comment_lines ]; then perl ./process_file.pl < $INFILE fi #### #!/usr/bin/env perl use strict; use warnings; $/=undef; open my $fh, "<", "test.in"; my $file = <$fh>; if ($file =~ m/^#/) { print "process me!\n"; }