#!/usr/bin/perl use strict; use warnings; for ( glob data*R.fa ) { my $Rfile = $_; s/R(?=\.fa)$/P/; my $Pfile = $_; # Your code here }