my $common = shift; if ( ! $common ) { print( "Please provide common filename as a parameter\n" ); exit( 1 ); } my @files = glob( "Test*.txt" ); if ( ! scalar(@files) ) { print( "No files found to process!\n" ); exit( 2 ); } foreach my $filename ( @files ) { next if ( $filename !~ m/^Test(\d+).txt$/ ); my $number = $1; my $outputname = "Final$number.txt"; `cat $common $filename >$outputname`; } print( "Done-diddily-un\n" ); exit( 0 );