#!/usr/bin/perl use strict; use warnings; for (@ARGV) { next if /P\./; # ignore the P files my ($base, $ext)= split /R/; #assume only one 'R' in the file name r_p_process ( $base."R".$ext, $base."P".$ext ) } sub r_p_process { my $r_file=shift; my $p_file=shift; print "processing the pair $r_file $p_file\n"; # do your funky stuff }