#!/usr/bin/env perl use strict; use warnings; use Getopt::Declare; # Note the '...' after each tag tells Getopt::Declare to gather arguments into an array reference. my $spec = <<'EOS'; -p ... input filename(s) [required] { defer{process(@INFILE)} } -f ... input filename(s) [required] { defer{process(@INFILE)} } EOS my $opts = Getopt::Declare->new($spec); sub process { @ARGV = @_; while(<>){ chomp; # do something here... } print $ARGV . "\n"; } __END__ $ perl test.pl -p out.txt -f in.txt -p out.txt -f out.txt out.txt in.txt out.txt out.txt